@expressive-ui/native 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +42 -2
  3. package/dist/Button.d.ts +48 -0
  4. package/dist/Button.d.ts.map +1 -0
  5. package/dist/Button.js +122 -0
  6. package/dist/Button.js.map +1 -0
  7. package/dist/Carousel.d.ts +13 -0
  8. package/dist/Carousel.d.ts.map +1 -0
  9. package/dist/Carousel.js +52 -0
  10. package/dist/Carousel.js.map +1 -0
  11. package/dist/Chips.d.ts +35 -0
  12. package/dist/Chips.d.ts.map +1 -0
  13. package/dist/Chips.js +138 -0
  14. package/dist/Chips.js.map +1 -0
  15. package/dist/Dialogs.d.ts +42 -0
  16. package/dist/Dialogs.d.ts.map +1 -0
  17. package/dist/Dialogs.js +115 -0
  18. package/dist/Dialogs.js.map +1 -0
  19. package/dist/ExpressiveCard.d.ts +20 -0
  20. package/dist/ExpressiveCard.d.ts.map +1 -0
  21. package/dist/ExpressiveCard.js +71 -0
  22. package/dist/ExpressiveCard.js.map +1 -0
  23. package/dist/Fab.d.ts +16 -0
  24. package/dist/Fab.d.ts.map +1 -0
  25. package/dist/Fab.js +104 -0
  26. package/dist/Fab.js.map +1 -0
  27. package/dist/Fields.d.ts +90 -0
  28. package/dist/Fields.d.ts.map +1 -0
  29. package/dist/Fields.js +211 -0
  30. package/dist/Fields.js.map +1 -0
  31. package/dist/Grid.d.ts +8 -0
  32. package/dist/Grid.d.ts.map +1 -0
  33. package/dist/Grid.js +16 -0
  34. package/dist/Grid.js.map +1 -0
  35. package/dist/Inputs.d.ts +33 -0
  36. package/dist/Inputs.d.ts.map +1 -0
  37. package/dist/Inputs.js +172 -0
  38. package/dist/Inputs.js.map +1 -0
  39. package/dist/List.d.ts +20 -0
  40. package/dist/List.d.ts.map +1 -0
  41. package/dist/List.js +222 -0
  42. package/dist/List.js.map +1 -0
  43. package/dist/Menu.d.ts +26 -0
  44. package/dist/Menu.d.ts.map +1 -0
  45. package/dist/Menu.js +117 -0
  46. package/dist/Menu.js.map +1 -0
  47. package/dist/Navigation.d.ts +34 -0
  48. package/dist/Navigation.d.ts.map +1 -0
  49. package/dist/Navigation.js +80 -0
  50. package/dist/Navigation.js.map +1 -0
  51. package/dist/Progress.d.ts +20 -0
  52. package/dist/Progress.d.ts.map +1 -0
  53. package/dist/Progress.js +93 -0
  54. package/dist/Progress.js.map +1 -0
  55. package/dist/Search.d.ts +50 -0
  56. package/dist/Search.d.ts.map +1 -0
  57. package/dist/Search.js +121 -0
  58. package/dist/Search.js.map +1 -0
  59. package/dist/Sheets.d.ts +44 -0
  60. package/dist/Sheets.d.ts.map +1 -0
  61. package/dist/Sheets.js +128 -0
  62. package/dist/Sheets.js.map +1 -0
  63. package/dist/Toolbar.d.ts +13 -0
  64. package/dist/Toolbar.d.ts.map +1 -0
  65. package/dist/Toolbar.js +38 -0
  66. package/dist/Toolbar.js.map +1 -0
  67. package/dist/Transition.d.ts +34 -0
  68. package/dist/Transition.d.ts.map +1 -0
  69. package/dist/Transition.js +93 -0
  70. package/dist/Transition.js.map +1 -0
  71. package/dist/index.d.ts +20 -0
  72. package/dist/index.d.ts.map +1 -0
  73. package/dist/index.js +20 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/primitives.d.ts +41 -0
  76. package/dist/primitives.d.ts.map +1 -0
  77. package/dist/primitives.js +55 -0
  78. package/dist/primitives.js.map +1 -0
  79. package/dist/theme.d.ts +57 -0
  80. package/dist/theme.d.ts.map +1 -0
  81. package/dist/theme.js +89 -0
  82. package/dist/theme.js.map +1 -0
  83. package/package.json +53 -4
  84. package/src/Button.tsx +347 -0
  85. package/src/Carousel.tsx +108 -0
  86. package/src/Chips.tsx +292 -0
  87. package/src/Dialogs.tsx +252 -0
  88. package/src/ExpressiveCard.tsx +205 -0
  89. package/src/Fab.tsx +187 -0
  90. package/src/Fields.tsx +556 -0
  91. package/src/Grid.tsx +29 -0
  92. package/src/Inputs.tsx +290 -0
  93. package/src/List.tsx +295 -0
  94. package/src/Menu.tsx +238 -0
  95. package/src/Navigation.tsx +198 -0
  96. package/src/Progress.tsx +192 -0
  97. package/src/Search.tsx +351 -0
  98. package/src/Sheets.tsx +273 -0
  99. package/src/Toolbar.tsx +88 -0
  100. package/src/Transition.tsx +155 -0
  101. package/src/index.ts +19 -0
  102. package/src/primitives.tsx +110 -0
  103. package/src/theme.tsx +125 -0
package/src/Button.tsx ADDED
@@ -0,0 +1,347 @@
1
+ import { Children, createContext, useContext, useMemo, useState, type ReactNode } from 'react';
2
+ import { Animated, Pressable, StyleSheet, Text, View, type StyleProp, type ViewStyle } from 'react-native';
3
+ import {
4
+ ButtonGroupSizeContext,
5
+ buttonGroupGap,
6
+ resolveButton,
7
+ resolveIconButton,
8
+ resolveSegment,
9
+ resolveSplitButton,
10
+ SiblingIndexContext,
11
+ useButtonGroupSize,
12
+ useInteraction,
13
+ useSiblingIndex,
14
+ type ButtonSpec,
15
+ type InteractionState,
16
+ type RuntimeProps,
17
+ } from '@expressive-ui/core';
18
+ import {
19
+ BUTTON_GROUP_DEFAULTS,
20
+ type ButtonData,
21
+ type ButtonGroupData,
22
+ type ButtonSize,
23
+ type IconButtonData,
24
+ type SplitButtonData,
25
+ } from '@expressive-ui/schema';
26
+ import { elevation, tokens } from '@expressive-ui/tokens';
27
+ import { Icon, typeStyle, withAlpha } from './primitives.js';
28
+ import { LoadingIndicator } from './Progress.js';
29
+ import { useExpressiveTheme, useSpringValue } from './theme.js';
30
+
31
+ type ToggleProps = {
32
+ /** Torna o botão um toggle (estado "selected" acessível). undefined = botão comum. */
33
+ selected?: boolean;
34
+ onPress?: () => void;
35
+ style?: StyleProp<ViewStyle>;
36
+ };
37
+
38
+ // Qual filho do ButtonGroup está pressionado. No web isso é :active + :has(); aqui o grupo guarda o índice.
39
+ type GroupPress = { pressed: number | null; setPressed: (index: number | null) => void; count: number };
40
+ const GroupPressContext = createContext<GroupPress | null>(null);
41
+
42
+ /** Cantos por lado (início/fim), para o split button. Sem isso o botão usa o raio uniforme do spec. */
43
+ type Corners = (state: InteractionState) => { start: number; end: number };
44
+
45
+ /** Container, morph de cantos, alargamento no grupo, elevação e camada de estado comuns a todos os botões. */
46
+ function ButtonSurface({
47
+ spec,
48
+ label,
49
+ busy = false,
50
+ onPress,
51
+ corners,
52
+ grouped = true,
53
+ accessibility,
54
+ style,
55
+ children,
56
+ }: {
57
+ spec: ButtonSpec;
58
+ label: string;
59
+ busy?: boolean;
60
+ onPress?: () => void;
61
+ corners?: Corners;
62
+ /** false para as partes do split: o grupo alarga o split como um só item. */
63
+ grouped?: boolean;
64
+ accessibility?: { expanded?: boolean };
65
+ style?: StyleProp<ViewStyle>;
66
+ children: (content: string) => ReactNode;
67
+ }) {
68
+ const { colors, mode } = useExpressiveTheme();
69
+ const { state, handlers } = useInteraction(spec.disabled || busy);
70
+ const group = useContext(GroupPressContext);
71
+ const index = useSiblingIndex();
72
+ const phase = state.pressed ? 'pressed' : state.hovered ? 'hover' : 'rest';
73
+
74
+ const uniform = state.pressed ? spec.radius.pressed : spec.radius.rest;
75
+ const target = corners ? corners(state) : { start: uniform, end: uniform };
76
+ const start = useSpringValue(target.start, 'spatialFast');
77
+ const end = useSpringValue(target.end, 'spatialFast');
78
+ const layer = useSpringValue(phase === 'pressed' ? tokens.state.pressed : phase === 'hover' ? tokens.state.hover : 0, 'effectsDefault');
79
+
80
+ // Pressionado cresce `squish`; cada vizinho encolhe metade, então a linha mantém a largura.
81
+ // Nas pontas só há um vizinho, que cede o valor inteiro.
82
+ const pressedIndex = grouped ? group?.pressed ?? null : null;
83
+ const edge = pressedIndex !== null && group ? pressedIndex === 0 || pressedIndex === group.count - 1 : false;
84
+ const neighbor = Math.abs((pressedIndex ?? -9) - index) === 1;
85
+ const extra = pressedIndex === null ? 0 : pressedIndex === index ? spec.squish : neighbor ? -spec.squish / (edge && group!.count > 1 ? 1 : 2) : 0;
86
+ const width = useSpringValue((spec.width ?? 0) + extra, 'spatialFast');
87
+ const padding = useSpringValue(spec.paddingX + extra / 2, 'spatialFast');
88
+ const pressHandlers = grouped && group
89
+ ? {
90
+ ...handlers,
91
+ onPressIn: () => {
92
+ handlers.onPressIn();
93
+ group.setPressed(index);
94
+ },
95
+ onPressOut: () => {
96
+ handlers.onPressOut();
97
+ group.setPressed(null);
98
+ },
99
+ }
100
+ : handlers;
101
+
102
+ const content = withAlpha(colors[spec.content], spec.contentOpacity);
103
+ const radius = { borderTopLeftRadius: start, borderBottomLeftRadius: start, borderTopRightRadius: end, borderBottomRightRadius: end };
104
+ return (
105
+ <Pressable
106
+ accessibilityRole="button"
107
+ accessibilityLabel={label}
108
+ accessibilityState={{ disabled: spec.disabled, busy, selected: spec.selected ?? undefined, expanded: accessibility?.expanded }}
109
+ disabled={spec.disabled || busy}
110
+ onPress={onPress}
111
+ hitSlop={{ left: spec.hitSlop.x, right: spec.hitSlop.x, top: spec.hitSlop.y, bottom: spec.hitSlop.y }}
112
+ {...pressHandlers}
113
+ >
114
+ {/* Sombra na view externa, recorte dos cantos na interna (como o CardSurface). */}
115
+ <Animated.View style={[{ ...radius, boxShadow: elevation(mode, spec.elevation[phase]) }, style]}>
116
+ <Animated.View
117
+ style={{
118
+ ...radius,
119
+ height: spec.height,
120
+ width: spec.width ? width : undefined,
121
+ paddingHorizontal: spec.width ? 0 : padding,
122
+ gap: spec.gap,
123
+ flexDirection: 'row',
124
+ alignItems: 'center',
125
+ justifyContent: 'center',
126
+ overflow: 'hidden',
127
+ backgroundColor: spec.container ? withAlpha(colors[spec.container], spec.containerOpacity) : 'transparent',
128
+ borderWidth: spec.borderWidth,
129
+ borderColor: spec.border ? withAlpha(colors[spec.border], spec.containerOpacity) : undefined,
130
+ }}
131
+ >
132
+ <Animated.View pointerEvents="none" style={[StyleSheet.absoluteFill, { backgroundColor: colors[spec.stateLayer], opacity: layer }]} />
133
+ {children(content)}
134
+ </Animated.View>
135
+ </Animated.View>
136
+ </Pressable>
137
+ );
138
+ }
139
+
140
+ export type ButtonProps = ButtonData &
141
+ RuntimeProps &
142
+ ToggleProps & {
143
+ /** Troca o ícone por um LoadingIndicator e ignora toques, sem esmaecer o botão. */
144
+ loading?: boolean;
145
+ };
146
+
147
+ export function Button({ onPress, onAction, index: _, children: __, selected, loading = false, style, ...data }: ButtonProps) {
148
+ const groupSize = useButtonGroupSize();
149
+ const spec = resolveButton({ ...data, size: data.size ?? groupSize }, { selected });
150
+ const press = onPress ?? (onAction ? () => onAction(data.action) : undefined);
151
+ return (
152
+ <ButtonSurface spec={spec} label={data.action.label} busy={loading} onPress={press} style={style}>
153
+ {(content) => (
154
+ <>
155
+ {loading ? (
156
+ <LoadingIndicator size={spec.iconSize + 4} tint={content} label={data.action.label} />
157
+ ) : data.icon ? (
158
+ <Icon name={data.icon} size={spec.iconSize} tint={content} filled={spec.iconFilled} />
159
+ ) : null}
160
+ <Text numberOfLines={1} style={[typeStyle(spec.type), { color: content }]}>
161
+ {data.action.label}
162
+ </Text>
163
+ </>
164
+ )}
165
+ </ButtonSurface>
166
+ );
167
+ }
168
+
169
+ export type IconButtonProps = IconButtonData & RuntimeProps & ToggleProps;
170
+
171
+ export function IconButton({ onPress, onAction, index: _, children: __, selected, style, ...data }: IconButtonProps) {
172
+ const groupSize = useButtonGroupSize();
173
+ const spec = resolveIconButton({ ...data, size: data.size ?? groupSize }, { selected });
174
+ const press = onPress ?? (onAction ? () => onAction(data.action) : undefined);
175
+ return (
176
+ <ButtonSurface spec={spec} label={data.action.label} onPress={press} style={style}>
177
+ {(content) => <Icon name={data.icon} size={spec.iconSize} tint={content} filled={spec.iconFilled} />}
178
+ </ButtonSurface>
179
+ );
180
+ }
181
+
182
+ const JUSTIFY = { start: 'flex-start', center: 'center', end: 'flex-end', stretch: 'flex-start' } as const;
183
+
184
+ export type ButtonGroupProps = ButtonGroupData & RuntimeProps & { style?: StyleProp<ViewStyle> };
185
+
186
+ /** Button group padrão do M3 Expressive: o pressionado alarga e os vizinhos encolhem. */
187
+ export function ButtonGroup({ size, align = BUTTON_GROUP_DEFAULTS.align, style, children }: ButtonGroupProps) {
188
+ const [pressed, setPressed] = useState<number | null>(null);
189
+ const items = Children.toArray(children);
190
+ const press = useMemo(() => ({ pressed, setPressed, count: items.length }), [pressed, items.length]);
191
+ return (
192
+ <View style={[{ flexDirection: 'row', flexWrap: 'wrap', alignItems: 'center', gap: buttonGroupGap(size), justifyContent: JUSTIFY[align] }, style]}>
193
+ <GroupPressContext.Provider value={press}>
194
+ <ButtonGroupSizeContext.Provider value={size}>
195
+ {items.map((child, i) => (
196
+ <SiblingIndexContext.Provider key={i} value={i}>
197
+ {align === 'stretch' ? <View style={{ flexGrow: 1, flexBasis: 0 }}>{child}</View> : child}
198
+ </SiblingIndexContext.Provider>
199
+ ))}
200
+ </ButtonGroupSizeContext.Provider>
201
+ </GroupPressContext.Provider>
202
+ </View>
203
+ );
204
+ }
205
+
206
+ export type SplitButtonProps = SplitButtonData &
207
+ RuntimeProps & {
208
+ onPress?: () => void;
209
+ onMenuPress?: () => void;
210
+ /** Menu aberto: o botão de menu fica circular e a seta gira. */
211
+ menuOpen?: boolean;
212
+ style?: StyleProp<ViewStyle>;
213
+ };
214
+
215
+ export function SplitButton({ onPress, onMenuPress, onAction, index: _, children: __, menuOpen = false, style, ...data }: SplitButtonProps) {
216
+ const groupSize = useButtonGroupSize();
217
+ const spec = resolveSplitButton({ ...data, size: data.size ?? groupSize }, { menuOpen });
218
+ const press = onPress ?? (onAction ? () => onAction(data.action) : undefined);
219
+ const menu = onMenuPress ?? (onAction ? () => onAction(data.menuAction) : undefined);
220
+ const { corners } = spec;
221
+ const inner = (state: InteractionState) => (state.pressed ? corners.innerPressed : state.hovered ? corners.innerHover : corners.inner);
222
+ const turn = useSpringValue(menuOpen ? 1 : 0, 'spatialDefault');
223
+ const rotate = turn.interpolate({ inputRange: [0, 1], outputRange: ['0deg', '180deg'] });
224
+ return (
225
+ <View style={[{ flexDirection: 'row', gap: spec.gap }, style]}>
226
+ <ButtonSurface spec={spec.leading} label={data.action.label} onPress={press} grouped={false} corners={(state) => ({ start: corners.outer, end: inner(state) })}>
227
+ {(content) => (
228
+ <>
229
+ {data.icon ? <Icon name={data.icon} size={spec.leading.iconSize} tint={content} /> : null}
230
+ <Text numberOfLines={1} style={[typeStyle(spec.leading.type), { color: content }]}>
231
+ {data.action.label}
232
+ </Text>
233
+ </>
234
+ )}
235
+ </ButtonSurface>
236
+ <ButtonSurface
237
+ spec={spec.trailing}
238
+ label={data.menuAction.label}
239
+ onPress={menu}
240
+ grouped={false}
241
+ accessibility={{ expanded: menuOpen }}
242
+ corners={(state) => (menuOpen ? { start: corners.open, end: corners.open } : { start: inner(state), end: corners.outer })}
243
+ >
244
+ {(content) => (
245
+ <Animated.View style={{ transform: [{ rotate }] }}>
246
+ <Icon name={spec.menuIcon} size={spec.trailing.iconSize} tint={content} />
247
+ </Animated.View>
248
+ )}
249
+ </ButtonSurface>
250
+ </View>
251
+ );
252
+ }
253
+
254
+ export type ConnectedOption<V extends string> = { value: V; label: string; icon?: string; disabled?: boolean };
255
+
256
+ export type ConnectedButtonGroupProps<V extends string> = {
257
+ options: readonly ConnectedOption<V>[];
258
+ value: V | null;
259
+ onChange?: (value: V) => void;
260
+ label: string;
261
+ size?: Extract<ButtonSize, 'xs' | 'sm' | 'md'>;
262
+ disabled?: boolean;
263
+ style?: StyleProp<ViewStyle>;
264
+ };
265
+
266
+ /** Grupo de botões conectados (escolha única), portado do ConnectedButtonGroup do mobile-app-rhosse. */
267
+ export function ConnectedButtonGroup<V extends string>({ options, value, onChange, label, size = 'sm', disabled, style }: ConnectedButtonGroupProps<V>) {
268
+ return (
269
+ <View accessibilityRole="radiogroup" accessibilityLabel={label} style={[{ flexDirection: 'row', gap: 2, opacity: disabled ? 0.5 : 1 }, style]}>
270
+ {options.map((option, index) => (
271
+ <Segment
272
+ key={option.value}
273
+ option={option}
274
+ size={size}
275
+ selected={option.value === value}
276
+ first={index === 0}
277
+ last={index === options.length - 1}
278
+ disabled={Boolean(disabled || option.disabled)}
279
+ onPress={() => onChange?.(option.value)}
280
+ />
281
+ ))}
282
+ </View>
283
+ );
284
+ }
285
+
286
+ // Ao selecionar, os cantos internos viram pílula; ao pressionar, encolhem. Cor e cantos seguem molas.
287
+ function Segment({
288
+ option,
289
+ size,
290
+ selected,
291
+ first,
292
+ last,
293
+ disabled,
294
+ onPress,
295
+ }: {
296
+ option: ConnectedOption<string>;
297
+ size: ButtonSize;
298
+ selected: boolean;
299
+ first: boolean;
300
+ last: boolean;
301
+ disabled: boolean;
302
+ onPress: () => void;
303
+ }) {
304
+ const { colors } = useExpressiveTheme();
305
+ const seg = resolveSegment(size, selected);
306
+ const { state, handlers } = useInteraction(disabled);
307
+ const inner = selected ? seg.radius.selected : state.pressed ? seg.radius.pressed : seg.radius.inner;
308
+ const start = useSpringValue(first ? seg.radius.outer : inner, 'spatialDefault');
309
+ const end = useSpringValue(last ? seg.radius.outer : inner, 'spatialDefault');
310
+ const on = useSpringValue(selected ? 1 : 0, 'effectsDefault');
311
+ const off = resolveSegment(size, false);
312
+ const background = on.interpolate({ inputRange: [0, 1], outputRange: [colors[off.container], colors[seg.container]] });
313
+ return (
314
+ <Pressable
315
+ accessibilityRole="radio"
316
+ accessibilityLabel={option.label}
317
+ accessibilityState={{ checked: selected, disabled }}
318
+ disabled={disabled}
319
+ onPress={onPress}
320
+ hitSlop={{ top: seg.hitSlop, bottom: seg.hitSlop }}
321
+ style={{ flex: 1 }}
322
+ {...handlers}
323
+ >
324
+ <Animated.View
325
+ style={{
326
+ height: seg.height,
327
+ paddingHorizontal: seg.paddingX,
328
+ gap: seg.gap,
329
+ flexDirection: 'row',
330
+ alignItems: 'center',
331
+ justifyContent: 'center',
332
+ backgroundColor: background,
333
+ borderTopLeftRadius: start,
334
+ borderBottomLeftRadius: start,
335
+ borderTopRightRadius: end,
336
+ borderBottomRightRadius: end,
337
+ opacity: option.disabled ? 0.45 : 1,
338
+ }}
339
+ >
340
+ {selected ? <Icon name="check" size={seg.iconSize} color={seg.content} /> : option.icon ? <Icon name={option.icon} size={seg.iconSize} color={seg.content} /> : null}
341
+ <Text numberOfLines={1} adjustsFontSizeToFit minimumFontScale={0.85} style={[typeStyle(seg.type), { color: colors[seg.content], flexShrink: 1 }]}>
342
+ {option.label}
343
+ </Text>
344
+ </Animated.View>
345
+ </Pressable>
346
+ );
347
+ }
@@ -0,0 +1,108 @@
1
+ import { useMemo, useRef, useState } from 'react';
2
+ import { Animated, Image, Pressable, ScrollView, StyleSheet, View, type StyleProp, type ViewStyle } from 'react-native';
3
+ import { carouselLayout, carouselMetrics, toneRoles, type CarouselSlot, type RuntimeProps } from '@expressive-ui/core';
4
+ import { CAROUSEL_DEFAULTS, type CarouselData } from '@expressive-ui/schema';
5
+ import { Icon, T } from './primitives.js';
6
+ import { useExpressiveTheme } from './theme.js';
7
+
8
+ export type CarouselProps = CarouselData &
9
+ RuntimeProps & {
10
+ onItemPress?: (id: string) => void;
11
+ style?: StyleProp<ViewStyle>;
12
+ };
13
+
14
+ /**
15
+ * MultiBrowseCarousel do mobile-app-rhosse generalizado: o layout de cada foco vem do core e a
16
+ * rolagem interpola posição e largura de cada item (grande encolhe e sai, o próximo cresce).
17
+ */
18
+ export function Carousel({ items, variant = CAROUSEL_DEFAULTS.variant, height = CAROUSEL_DEFAULTS.height, label, onAction, onItemPress, index: _, children: __, style }: CarouselProps) {
19
+ const { colors } = useExpressiveTheme();
20
+ const [width, setWidth] = useState(0);
21
+ const scrollX = useRef(new Animated.Value(0)).current;
22
+ const count = items.length;
23
+ const m = carouselMetrics(width || 1, count, { variant, height });
24
+
25
+ const animated = useMemo(() => {
26
+ if (!width) return [];
27
+ const layouts = Array.from({ length: count }, (_, focus) => carouselLayout(focus, count, m));
28
+ // interpolate precisa de pelo menos dois pontos.
29
+ const inputRange = count > 1 ? layouts.map((__, focus) => focus * m.step) : [0, 1];
30
+ const series = (pick: (slot: CarouselSlot) => number, i: number) => {
31
+ const values = layouts.map((slots) => pick(slots[i]!));
32
+ return count > 1 ? values : [values[0]!, values[0]!];
33
+ };
34
+ return items.map((__, i) => {
35
+ const at = (pick: (slot: CarouselSlot) => number) => scrollX.interpolate({ inputRange, outputRange: series(pick, i), extrapolate: 'clamp' });
36
+ return {
37
+ width: at((slot) => slot.width),
38
+ left: Animated.add(scrollX, at((slot) => slot.left)),
39
+ shift: at((slot) => (slot.width - m.large) / 2),
40
+ label: at((slot) => (slot.width >= m.medium - 1 ? 1 : 0)),
41
+ focus: at((slot) => (slot.width >= m.large - 1 ? 1 : 0)),
42
+ };
43
+ });
44
+ }, [width, count, variant, height, scrollX]);
45
+
46
+ return (
47
+ <View accessibilityLabel={label} onLayout={(e) => setWidth(e.nativeEvent.layout.width)} style={style}>
48
+ {width ? (
49
+ <ScrollView
50
+ horizontal
51
+ showsHorizontalScrollIndicator={false}
52
+ snapToInterval={m.step}
53
+ decelerationRate="fast"
54
+ disableIntervalMomentum
55
+ scrollEventThrottle={16}
56
+ onScroll={Animated.event([{ nativeEvent: { contentOffset: { x: scrollX } } }], { useNativeDriver: false })}
57
+ contentContainerStyle={{ width: m.scrollWidth, height: m.height }}
58
+ >
59
+ {items.map((item, i) => {
60
+ const a = animated[i];
61
+ if (!a) return null;
62
+ const roles = toneRoles(item.media.tone && item.media.tone !== 'auto' ? item.media.tone : 'primary');
63
+ return (
64
+ <Animated.View
65
+ key={item.id}
66
+ style={{ position: 'absolute', top: 0, height: m.height, left: a.left, width: a.width, borderRadius: m.radius, overflow: 'hidden', backgroundColor: colors[roles.container] }}
67
+ >
68
+ <Pressable
69
+ accessibilityRole="button"
70
+ accessibilityLabel={item.action?.label ?? item.label}
71
+ onPress={() => (onItemPress ? onItemPress(item.id) : item.action && onAction?.(item.action))}
72
+ style={styles.fill}
73
+ >
74
+ {/* Conteúdo com a largura do grande, centralizado: encolher só recorta as bordas. */}
75
+ <Animated.View style={[styles.content, { width: m.large, transform: [{ translateX: a.shift }] }]}>
76
+ {item.media.src ? (
77
+ <Image source={{ uri: item.media.src }} accessibilityLabel={item.media.alt} style={StyleSheet.absoluteFill} resizeMode="cover" />
78
+ ) : item.media.icon ? (
79
+ <Icon name={item.media.icon} size={48} color={roles.onContainer} filled />
80
+ ) : null}
81
+ </Animated.View>
82
+ <Animated.View style={[styles.caption, { opacity: a.label }]}>
83
+ <T variant="titleMedium" emphasized numberOfLines={1} style={{ color: item.media.src ? '#fff' : colors[roles.onContainer] }}>
84
+ {item.label}
85
+ </T>
86
+ {item.supporting ? (
87
+ <Animated.Text numberOfLines={1} style={{ opacity: a.focus, color: item.media.src ? '#fff' : colors[roles.onContainer] }}>
88
+ {item.supporting}
89
+ </Animated.Text>
90
+ ) : null}
91
+ </Animated.View>
92
+ </Pressable>
93
+ </Animated.View>
94
+ );
95
+ })}
96
+ </ScrollView>
97
+ ) : (
98
+ <View style={{ height: m.height }} />
99
+ )}
100
+ </View>
101
+ );
102
+ }
103
+
104
+ const styles = StyleSheet.create({
105
+ fill: { flex: 1 },
106
+ content: { position: 'absolute', top: 0, bottom: 0, left: 0, alignItems: 'center', justifyContent: 'center' },
107
+ caption: { position: 'absolute', left: 16, right: 16, bottom: 14 },
108
+ });