mobile-design 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 (121) hide show
  1. package/LICENSE +21 -0
  2. package/LICENSE-Apache-2.0.txt +55 -0
  3. package/NOTICE +11 -0
  4. package/README.md +96 -2
  5. package/assets/fonts/MaterialSymbolsRounded.ttf +0 -0
  6. package/assets/fonts/MaterialSymbolsRounded.woff2 +0 -0
  7. package/assets/fonts/roboto/OFL.txt +93 -0
  8. package/assets/fonts/roboto/Roboto_400Regular.ttf +0 -0
  9. package/assets/fonts/roboto/Roboto_400Regular.woff2 +0 -0
  10. package/assets/fonts/roboto/Roboto_400Regular_Italic.ttf +0 -0
  11. package/assets/fonts/roboto/Roboto_400Regular_Italic.woff2 +0 -0
  12. package/assets/fonts/roboto/Roboto_500Medium.ttf +0 -0
  13. package/assets/fonts/roboto/Roboto_500Medium.woff2 +0 -0
  14. package/assets/fonts/roboto/Roboto_500Medium_Italic.ttf +0 -0
  15. package/assets/fonts/roboto/Roboto_500Medium_Italic.woff2 +0 -0
  16. package/assets/fonts/roboto/Roboto_600SemiBold.ttf +0 -0
  17. package/assets/fonts/roboto/Roboto_600SemiBold.woff2 +0 -0
  18. package/assets/fonts/roboto/Roboto_600SemiBold_Italic.ttf +0 -0
  19. package/assets/fonts/roboto/Roboto_600SemiBold_Italic.woff2 +0 -0
  20. package/assets/fonts/roboto/Roboto_700Bold.ttf +0 -0
  21. package/assets/fonts/roboto/Roboto_700Bold.woff2 +0 -0
  22. package/assets/fonts/roboto/Roboto_700Bold_Italic.ttf +0 -0
  23. package/assets/fonts/roboto/Roboto_700Bold_Italic.woff2 +0 -0
  24. package/assets/fonts/roboto/Roboto_800ExtraBold.ttf +0 -0
  25. package/assets/fonts/roboto/Roboto_800ExtraBold.woff2 +0 -0
  26. package/assets/fonts/roboto/Roboto_800ExtraBold_Italic.ttf +0 -0
  27. package/assets/fonts/roboto/Roboto_800ExtraBold_Italic.woff2 +0 -0
  28. package/assets/logo.svg +13 -0
  29. package/package.json +62 -3
  30. package/src/catalog.ts +683 -0
  31. package/src/color-scheme.ts +68 -0
  32. package/src/color.ts +35 -0
  33. package/src/components/action-surface.tsx +83 -0
  34. package/src/components/appbar-layout.ts +85 -0
  35. package/src/components/appbar-scroll-behavior.tsx +386 -0
  36. package/src/components/appbar.tsx +474 -0
  37. package/src/components/avatar.tsx +135 -0
  38. package/src/components/bottom-sheet-text-field.tsx +13 -0
  39. package/src/components/bottom-sheet-text-input.tsx +2 -0
  40. package/src/components/bottom-sheet-text-input.web.tsx +2 -0
  41. package/src/components/button-group.tsx +996 -0
  42. package/src/components/button.tsx +504 -0
  43. package/src/components/card.tsx +284 -0
  44. package/src/components/carousel-full-screen.tsx +374 -0
  45. package/src/components/carousel-layout.ts +418 -0
  46. package/src/components/carousel-scroll-controller.tsx +303 -0
  47. package/src/components/carousel-vertical-layout.ts +92 -0
  48. package/src/components/carousel-vertical.tsx +505 -0
  49. package/src/components/carousel.tsx +678 -0
  50. package/src/components/choice-motion.tsx +108 -0
  51. package/src/components/choice-types.ts +52 -0
  52. package/src/components/choice.tsx +400 -0
  53. package/src/components/choice.web.ts +1 -0
  54. package/src/components/circular-progress-status.tsx +218 -0
  55. package/src/components/container-transform.tsx +304 -0
  56. package/src/components/content.tsx +1450 -0
  57. package/src/components/date-picker-calendar.tsx +933 -0
  58. package/src/components/date-picker-months.tsx +102 -0
  59. package/src/components/date-picker-utils.ts +96 -0
  60. package/src/components/date-picker.tsx +641 -0
  61. package/src/components/dialog.tsx +340 -0
  62. package/src/components/docked-date-picker.tsx +525 -0
  63. package/src/components/drawer.tsx +248 -0
  64. package/src/components/fab.tsx +1221 -0
  65. package/src/components/focus-order.ts +40 -0
  66. package/src/components/full-screen-dialog.tsx +234 -0
  67. package/src/components/icon-button.tsx +72 -0
  68. package/src/components/list-focus.tsx +182 -0
  69. package/src/components/list-reorder.tsx +349 -0
  70. package/src/components/loading-indicator.tsx +378 -0
  71. package/src/components/menu.tsx +1091 -0
  72. package/src/components/navigation-bar.tsx +390 -0
  73. package/src/components/navigation-focus.ts +45 -0
  74. package/src/components/navigation-rail-layout.ts +53 -0
  75. package/src/components/navigation.tsx +682 -0
  76. package/src/components/popup.tsx +624 -0
  77. package/src/components/press-scope.ts +17 -0
  78. package/src/components/progress-indicator-paths.ts +254 -0
  79. package/src/components/progress-indicator.tsx +570 -0
  80. package/src/components/progress.tsx +39 -0
  81. package/src/components/pull-to-refresh.tsx +379 -0
  82. package/src/components/rich-tooltip.tsx +183 -0
  83. package/src/components/search-icon-button.tsx +8 -0
  84. package/src/components/search-trigger.tsx +28 -0
  85. package/src/components/search-view.tsx +790 -0
  86. package/src/components/searchbar.tsx +190 -0
  87. package/src/components/segmented-buttons.tsx +456 -0
  88. package/src/components/selection-controls.tsx +760 -0
  89. package/src/components/sheets.tsx +1027 -0
  90. package/src/components/slider.tsx +1290 -0
  91. package/src/components/snackbar.tsx +430 -0
  92. package/src/components/split-button.tsx +525 -0
  93. package/src/components/swipe-list-item.tsx +793 -0
  94. package/src/components/switch.tsx +319 -0
  95. package/src/components/tabs-pager.tsx +241 -0
  96. package/src/components/tabs-pager.web.tsx +110 -0
  97. package/src/components/tabs.tsx +759 -0
  98. package/src/components/text-field.tsx +673 -0
  99. package/src/components/time-picker.tsx +1248 -0
  100. package/src/components/toolbar.tsx +590 -0
  101. package/src/components/tooltip.tsx +273 -0
  102. package/src/components/web-choice.tsx +572 -0
  103. package/src/core.tsx +169 -0
  104. package/src/font-assets.ts +28 -0
  105. package/src/font-assets.web.ts +25 -0
  106. package/src/index.ts +139 -0
  107. package/src/material-symbol-codepoints.ts +67 -0
  108. package/src/material-symbol-paths.ts +340 -0
  109. package/src/material-symbols.tsx +155 -0
  110. package/src/native-modal.tsx +50 -0
  111. package/src/outside-interaction.tsx +39 -0
  112. package/src/paper-icon-aliases.ts +147 -0
  113. package/src/paper-internals.d.ts +15 -0
  114. package/src/paper-motion-bridge.tsx +11 -0
  115. package/src/paper-motion.tsx +24 -0
  116. package/src/primitives.tsx +13 -0
  117. package/src/ripple.tsx +7 -0
  118. package/src/ripple.web.tsx +108 -0
  119. package/src/scroll-indicators.ts +12 -0
  120. package/src/typography.ts +9 -0
  121. package/src/web-accessibility.ts +19 -0
@@ -0,0 +1,790 @@
1
+ /// <reference path="../paper-internals.d.ts" />
2
+ import { getScrollIndicatorProps, type ScrollIndicatorOptions } from '../scroll-indicators';
3
+ import { NativeModal as Modal } from '../native-modal';
4
+ import {
5
+ useCallback,
6
+ useContext,
7
+ useEffect,
8
+ useLayoutEffect,
9
+ useRef,
10
+ useState,
11
+ type ComponentProps,
12
+ type ComponentRef,
13
+ type ReactNode,
14
+ } from 'react';
15
+ import {
16
+ AccessibilityInfo,
17
+ FlatList,
18
+ Keyboard,
19
+ KeyboardAvoidingView,
20
+ Platform,
21
+ Pressable,
22
+ View,
23
+ useWindowDimensions,
24
+ type ColorValue,
25
+ type StyleProp,
26
+ type TextInputInstance,
27
+ type ViewStyle,
28
+ } from 'react-native';
29
+ import { Text, useLocale, useTheme, type Theme } from 'react-native-paper';
30
+ import { ReduceMotionContext } from 'react-native-paper/lib/module/theme/accessibility/ReduceMotionContext';
31
+ import Animated, { interpolateColor, useAnimatedStyle } from 'react-native-reanimated';
32
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
33
+ import { useOverlayPresence } from './sheets';
34
+ import { SearchIconButton } from './search-icon-button';
35
+ import { Searchbar } from './searchbar';
36
+ import { SearchTrigger } from './search-trigger';
37
+ import { Divider, List } from './content';
38
+
39
+ type SearchIcon = ComponentProps<typeof List.Icon>['icon'];
40
+ type SearchInputHandle = Pick<TextInputInstance, 'setNativeProps' | 'isFocused' | 'clear' | 'blur' | 'focus' | 'setSelection'>;
41
+ export type SearchResult = {
42
+ key: string;
43
+ title: string;
44
+ description?: string;
45
+ icon?: SearchIcon;
46
+ disabled?: boolean;
47
+ accessibilityLabel?: string;
48
+ };
49
+ export type SearchViewProps = {
50
+ /** Scrollbars are opt-in for this component only; both axes are hidden by default. */
51
+ scrollIndicators?: ScrollIndicatorOptions;
52
+ open: boolean;
53
+ onOpenChange: (open: boolean) => void;
54
+ /** Called after the outgoing view is removed; interrupted exits do not notify. */
55
+ onClosed?: () => void;
56
+ value: string;
57
+ onChangeText: (value: string) => void;
58
+ onSearch: (query: string) => void;
59
+ results?: readonly SearchResult[];
60
+ /** Announced when custom results change, including empty and loading states. */
61
+ resultsAccessibilityLabel?: string;
62
+ onResultPress?: (result: SearchResult) => void;
63
+ renderResults?: (state: { containerColor: ColorValue }) => ReactNode;
64
+ loading?: boolean;
65
+ placeholder?: string;
66
+ emptyContent?: ReactNode;
67
+ supportingContent?: ReactNode;
68
+ /** Persistent contextual controls below the scrolling results. */
69
+ footerContent?: ReactNode;
70
+ /** Keep the footer at the window bottom, covered by the keyboard, when false. */
71
+ footerAvoidsKeyboard?: boolean;
72
+ /** Color of the existing reserved space below the footer; does not add padding. */
73
+ footerContainerColor?: ColorValue;
74
+ /** Alternate measured entry; use SearchTrigger for a capsule, or IconButton/Chip for their own target shapes. */
75
+ renderTrigger?: (state: { open: () => void; disabled: boolean; expanded: boolean }) => ReactNode;
76
+ trailingContent?: ReactNode;
77
+ /** Independent controls inside the expanded input, alongside its clear action. */
78
+ inputTrailingContent?: ReactNode;
79
+ trailingActions?: readonly { key: string; icon: SearchIcon; label: string; onPress: () => void; disabled?: boolean; testID?: string }[];
80
+ leadingIcon?: SearchIcon;
81
+ onLeadingPress?: () => void;
82
+ /** Closed entry point only; an app bar may paint its animated search container. */
83
+ barContainerColor?: ColorValue;
84
+ barTextAlign?: 'start' | 'center';
85
+ autoFocus?: boolean;
86
+ closeOnSubmit?: boolean;
87
+ closeOnSelect?: boolean;
88
+ disabled?: boolean;
89
+ variant?: 'contained' | 'divided';
90
+ presentation?: 'full-screen' | 'docked' | 'auto';
91
+ style?: StyleProp<ViewStyle>;
92
+ testID?: string;
93
+ };
94
+
95
+ type Anchor = { x: number; y: number; width: number; height: number };
96
+
97
+ function SearchInputHeader({
98
+ contained,
99
+ animatedStyle,
100
+ ...props
101
+ }: {
102
+ contained: boolean;
103
+ animatedStyle: ComponentProps<typeof Animated.View>['style'];
104
+ style: StyleProp<ViewStyle>;
105
+ children: ReactNode;
106
+ testID: string;
107
+ }) {
108
+ // The baseline input needs a plain native host; a transform on its animated
109
+ // ancestor can hide editable text in iOS, even when that transform is zero.
110
+ return contained ? <Animated.View {...props} style={[props.style, animatedStyle]} /> : <View {...props} />;
111
+ }
112
+
113
+ /** A controlled search bar and full-screen search view; results and actions belong to the caller. */
114
+ export function SearchView({
115
+ scrollIndicators,
116
+ open,
117
+ onOpenChange,
118
+ onClosed,
119
+ value,
120
+ onChangeText,
121
+ onSearch,
122
+ results = [],
123
+ resultsAccessibilityLabel,
124
+ onResultPress,
125
+ renderResults,
126
+ loading = false,
127
+ placeholder = 'Buscar',
128
+ emptyContent,
129
+ supportingContent,
130
+ footerContent,
131
+ footerAvoidsKeyboard = true,
132
+ footerContainerColor,
133
+ renderTrigger,
134
+ trailingContent,
135
+ inputTrailingContent,
136
+ trailingActions = [],
137
+ leadingIcon = 'search',
138
+ onLeadingPress,
139
+ barContainerColor,
140
+ barTextAlign = 'start',
141
+ autoFocus = true,
142
+ closeOnSubmit = false,
143
+ closeOnSelect = true,
144
+ disabled = false,
145
+ variant = 'contained',
146
+ presentation = 'auto',
147
+ style,
148
+ testID = 'mobile-search',
149
+ }: SearchViewProps) {
150
+ const theme = useTheme<Theme>();
151
+ const rtl = useLocale().direction === 'rtl';
152
+ const insets = useSafeAreaInsets();
153
+ const window = useWindowDimensions();
154
+ const reduced = useContext(ReduceMotionContext) || theme.animation.scale === 0;
155
+ const bar = useRef<ComponentRef<typeof View>>(null);
156
+ const input = useRef<SearchInputHandle>(null);
157
+ const [anchor, setAnchor] = useState<Anchor>();
158
+ const [trailingWidth, setTrailingWidth] = useState(0);
159
+ const [keyboardVisible, setKeyboardVisible] = useState(false);
160
+ const [barFocused, setBarFocused] = useState(false);
161
+ const latest = useRef({
162
+ open,
163
+ disabled,
164
+ onOpenChange,
165
+ onChangeText,
166
+ value,
167
+ loading,
168
+ onSearch,
169
+ onResultPress,
170
+ results,
171
+ closeOnSelect,
172
+ closeOnSubmit,
173
+ });
174
+ const focusFrame = useRef<number | undefined>(undefined);
175
+ const alive = useRef(true);
176
+ const measurementRevision = useRef(0);
177
+ const { present, progress } = useOverlayPresence(
178
+ open,
179
+ reduced ? 0 : theme.motion.duration.medium4 * theme.animation.scale,
180
+ variant === 'contained' ? 'search' : 'timing',
181
+ undefined,
182
+ // Exit completes on arrival at the entry; an invisible spring tail must
183
+ // not keep its modal blocking the restored bar and contextual actions.
184
+ { ready: anchor !== undefined, overshootClamping: variant !== 'contained' || !open }
185
+ );
186
+ const wasPresent = useRef(present);
187
+ const previousOpen = useRef(open);
188
+ const docked = presentation === 'docked' || (presentation === 'auto' && window.width >= 600);
189
+ const panelWidth = Math.min(720, Math.max(360, anchor?.width ?? 360), Math.max(1, window.width - insets.left - insets.right - 32));
190
+ const panelHeight = Math.min((window.height * 2) / 3, Math.max(1, window.height - insets.top - insets.bottom - 32));
191
+ const panelX = Math.max(insets.left + 16, Math.min(anchor?.x ?? 16, window.width - insets.right - panelWidth - 16));
192
+ const panelY = Math.max(insets.top + 16, Math.min(anchor?.y ?? insets.top + 16, window.height - insets.bottom - panelHeight - 16));
193
+ const background = variant === 'contained' && !docked ? theme.colors.surfaceContainerLow : theme.colors.surfaceContainerHigh;
194
+ const leadingColor = variant === 'contained' ? theme.colors.onSurfaceVariant : theme.colors.onSurface;
195
+ const inputMode = variant === 'contained' || docked ? 'bar' : 'view';
196
+ const fieldHeight = Math.max(inputMode === 'bar' ? 56 : 72, (theme.fonts.bodyLarge.lineHeight ?? 24) * window.fontScale + 8);
197
+ const fieldX = docked ? panelX : insets.left + (variant === 'contained' ? 12 : 0);
198
+ const fieldY = docked ? panelY : insets.top + (variant === 'contained' ? 8 : 0);
199
+ const fieldWidth = docked ? panelWidth : window.width - insets.left - insets.right - (variant === 'contained' ? 24 : 0);
200
+ const resultsStatus =
201
+ resultsAccessibilityLabel ??
202
+ (loading
203
+ ? 'Buscando…'
204
+ : !renderResults || results.length > 0
205
+ ? `${results.length} ${value ? (results.length === 1 ? 'resultado' : 'resultados') : results.length === 1 ? 'sugerencia' : 'sugerencias'}`
206
+ : undefined);
207
+ useEffect(() => {
208
+ if (Platform.OS !== 'ios' || !open || !resultsStatus) return;
209
+ let current = true;
210
+ // Android uses the live region below; iOS needs an explicit announcement.
211
+ // Wait for input feedback to settle and coalesce results while typing.
212
+ const timer = setTimeout(() => {
213
+ AccessibilityInfo.isScreenReaderEnabled().then((enabled) => {
214
+ if (current && enabled) AccessibilityInfo.announceForAccessibilityWithOptions(resultsStatus, { queue: true });
215
+ });
216
+ }, 300);
217
+ return () => {
218
+ current = false;
219
+ clearTimeout(timer);
220
+ };
221
+ }, [open, results, resultsStatus, value]);
222
+ useEffect(() => {
223
+ if (footerAvoidsKeyboard || Platform.OS !== 'android' || !present) return;
224
+ setKeyboardVisible(Keyboard.isVisible());
225
+ const show = Keyboard.addListener('keyboardDidShow', () => setKeyboardVisible(true));
226
+ const hide = Keyboard.addListener('keyboardDidHide', () => setKeyboardVisible(false));
227
+ return () => {
228
+ show.remove();
229
+ hide.remove();
230
+ };
231
+ }, [footerAvoidsKeyboard, present]);
232
+ useLayoutEffect(() => {
233
+ latest.current = {
234
+ open,
235
+ disabled,
236
+ onOpenChange,
237
+ onChangeText,
238
+ value,
239
+ loading,
240
+ onSearch,
241
+ onResultPress,
242
+ results,
243
+ closeOnSelect,
244
+ closeOnSubmit,
245
+ };
246
+ }, [disabled, open, onOpenChange, onChangeText, value, loading, onSearch, onResultPress, results, closeOnSelect, closeOnSubmit]);
247
+ useEffect(() => {
248
+ alive.current = true;
249
+ return () => {
250
+ alive.current = false;
251
+ measurementRevision.current++;
252
+ if (focusFrame.current !== undefined) cancelAnimationFrame(focusFrame.current);
253
+ };
254
+ }, []);
255
+ useEffect(() => {
256
+ const closed = wasPresent.current && !present && !open;
257
+ wasPresent.current = present;
258
+ if (closed) onClosed?.();
259
+ }, [onClosed, open, present]);
260
+ const measure = useCallback(() => {
261
+ const revision = ++measurementRevision.current;
262
+ bar.current?.measureInWindow((x, y, width, height) => {
263
+ if (
264
+ alive.current &&
265
+ revision === measurementRevision.current &&
266
+ [x, y, width, height].every(Number.isFinite) &&
267
+ width > 0 &&
268
+ height > 0
269
+ )
270
+ setAnchor((previous) =>
271
+ previous?.x === x && previous.y === y && previous.width === width && previous.height === height
272
+ ? previous
273
+ : { x, y, width, height }
274
+ );
275
+ });
276
+ }, [window.width, window.height]);
277
+ const close = useCallback(() => {
278
+ if (!alive.current || !latest.current.open) return;
279
+ measurementRevision.current++;
280
+ if (focusFrame.current !== undefined) cancelAnimationFrame(focusFrame.current);
281
+ input.current?.blur();
282
+ Keyboard.dismiss();
283
+ latest.current.onOpenChange(false);
284
+ }, []);
285
+ const enter = useCallback(() => {
286
+ if (!alive.current || latest.current.disabled) return;
287
+ measure();
288
+ latest.current.onOpenChange(true);
289
+ }, [measure]);
290
+ const focus = useCallback(() => {
291
+ if (focusFrame.current !== undefined) cancelAnimationFrame(focusFrame.current);
292
+ if (!autoFocus || !latest.current.open || latest.current.disabled) return;
293
+ focusFrame.current = requestAnimationFrame(() => {
294
+ if (alive.current && latest.current.open && !latest.current.disabled) input.current?.focus();
295
+ });
296
+ }, [autoFocus]);
297
+ useEffect(() => {
298
+ if (open) measure();
299
+ else {
300
+ measurementRevision.current++;
301
+ input.current?.blur();
302
+ // A closed instance can resize alongside another active search.
303
+ if (previousOpen.current) Keyboard.dismiss();
304
+ }
305
+ previousOpen.current = open;
306
+ }, [measure, open]);
307
+ useEffect(() => {
308
+ if (present && open) focus();
309
+ }, [focus, open, present]);
310
+ const submit = () => {
311
+ const current = latest.current;
312
+ if (!alive.current || !current.open || current.disabled || current.loading) return;
313
+ input.current?.blur();
314
+ Keyboard.dismiss();
315
+ current.onSearch(current.value);
316
+ if (current.closeOnSubmit) close();
317
+ };
318
+ const change = useCallback((next: string) => {
319
+ const current = latest.current;
320
+ if (alive.current && current.open && !current.disabled) current.onChangeText(next);
321
+ }, []);
322
+ const backgroundStyle = useAnimatedStyle(() => {
323
+ const amount = Math.max(0, Math.min(1, progress.get()));
324
+ const origin = anchor ?? { x: 0, y: insets.top, width: window.width, height: 56 };
325
+ if (variant === 'contained')
326
+ return {
327
+ left: 0,
328
+ top: 0,
329
+ width: window.width,
330
+ height: window.height,
331
+ borderRadius: 0,
332
+ backgroundColor: background,
333
+ opacity: docked ? 0 : amount,
334
+ };
335
+ return {
336
+ opacity: 1,
337
+ backgroundColor:
338
+ typeof background === 'string' && typeof (barContainerColor ?? theme.colors.surfaceContainerHigh) === 'string'
339
+ ? interpolateColor(amount, [0, 1], [barContainerColor ?? theme.colors.surfaceContainerHigh, background] as string[])
340
+ : background,
341
+ left: origin.x + ((docked ? panelX : 0) - origin.x) * amount,
342
+ top: origin.y + ((docked ? panelY : 0) - origin.y) * amount,
343
+ width: origin.width + ((docked ? panelWidth : window.width) - origin.width) * amount,
344
+ height: origin.height + ((docked ? panelHeight : window.height) - origin.height) * amount,
345
+ borderRadius: docked ? 28 : 28 * (1 - amount),
346
+ };
347
+ });
348
+ // Animate the empty capsule independently: text and glyphs never stretch.
349
+ const capsuleStyle = useAnimatedStyle(() => {
350
+ const amount = reduced ? 1 : progress.get();
351
+ const origin = anchor ?? { x: fieldX, y: fieldY, width: fieldWidth, height: fieldHeight };
352
+ return {
353
+ left: origin.x + (fieldX - origin.x) * amount,
354
+ top: origin.y + (fieldY - origin.y) * amount,
355
+ width: Math.max(1, origin.width + (fieldWidth - origin.width) * amount),
356
+ height: Math.max(1, origin.height + (fieldHeight - origin.height) * amount),
357
+ borderRadius: 28,
358
+ };
359
+ });
360
+ const headerStyle = useAnimatedStyle(() => {
361
+ const amount = reduced ? 1 : progress.get();
362
+ const origin = anchor ?? { x: fieldX, y: fieldY, width: fieldWidth };
363
+ return variant === 'contained'
364
+ ? {
365
+ opacity: !open || origin.width < 128 ? Math.max(0, Math.min(1, amount)) : 1,
366
+ transform: [{ translateX: (origin.x - fieldX) * (1 - amount) }, { translateY: (origin.y - fieldY) * (1 - amount) }],
367
+ }
368
+ : { opacity: 1, transform: [{ translateX: 0 }, { translateY: 0 }] };
369
+ });
370
+ const contentStyle = useAnimatedStyle(() =>
371
+ variant === 'contained'
372
+ ? { opacity: 1, transform: [{ translateY: 0 }] }
373
+ : { opacity: Math.max(0, Math.min(1, progress.get())), transform: [{ translateY: (1 - progress.get()) * 16 }] }
374
+ );
375
+ const resultsStyle = useAnimatedStyle(() =>
376
+ variant === 'contained'
377
+ ? {
378
+ opacity: Math.max(0, Math.min(1, (progress.get() - 0.2) / 0.8)),
379
+ transform: [{ translateY: reduced ? 0 : (1 - progress.get()) * 16 }],
380
+ }
381
+ : { opacity: 1, transform: [{ translateY: 0 }] }
382
+ );
383
+ const scrimStyle = useAnimatedStyle(() => ({ opacity: 0.32 * Math.max(0, Math.min(1, progress.get())) }));
384
+ const inputActions =
385
+ inputTrailingContent != null ? (
386
+ <View
387
+ style={{
388
+ direction: 'ltr',
389
+ flexDirection: rtl ? 'row-reverse' : 'row',
390
+ alignItems: 'center',
391
+ }}
392
+ >
393
+ {value.length > 0 && !loading ? (
394
+ <SearchIconButton
395
+ icon="close"
396
+ iconColor={leadingColor}
397
+ accessibilityLabel="Borrar búsqueda"
398
+ disabled={!open || disabled || loading}
399
+ onPress={() => {
400
+ if (!alive.current || !latest.current.open || latest.current.disabled || latest.current.loading) return;
401
+ change('');
402
+ input.current?.focus();
403
+ }}
404
+ testID={`${testID}-clear`}
405
+ />
406
+ ) : null}
407
+ {inputTrailingContent}
408
+ </View>
409
+ ) : undefined;
410
+ const footer = (
411
+ <>
412
+ {footerContent}
413
+ {/* KAV's iOS padding replaces style.paddingBottom, so reserve this space as a child. */}
414
+ <View
415
+ pointerEvents="none"
416
+ accessible={false}
417
+ style={{
418
+ height: docked ? 8 : insets.bottom,
419
+ flexShrink: 0,
420
+ backgroundColor: footerContent != null ? footerContainerColor : undefined,
421
+ }}
422
+ testID={`${testID}-footer-safe-area`}
423
+ />
424
+ </>
425
+ );
426
+ return (
427
+ <>
428
+ <View
429
+ ref={bar}
430
+ collapsable={false}
431
+ onLayout={measure}
432
+ pointerEvents={present ? 'none' : 'auto'}
433
+ accessibilityElementsHidden={present}
434
+ importantForAccessibility={present ? 'no-hide-descendants' : 'auto'}
435
+ style={[{ maxWidth: 720 }, style]}
436
+ >
437
+ {renderTrigger ? (
438
+ renderTrigger({ open: enter, disabled, expanded: open })
439
+ ) : (
440
+ <>
441
+ <SearchTrigger
442
+ onFocus={(event) =>
443
+ setBarFocused(
444
+ Platform.OS === 'web' && (event.currentTarget as unknown as HTMLElement).matches(':focus-visible')
445
+ )
446
+ }
447
+ onBlur={() => setBarFocused(false)}
448
+ onPressIn={(event) => {
449
+ if (!(event.nativeEvent as { key?: string }).key) setBarFocused(false);
450
+ }}
451
+ accessibilityRole="button"
452
+ accessibilityLabel={value ? `${placeholder}: ${value}` : placeholder}
453
+ accessibilityHint="Abre la vista de búsqueda"
454
+ accessibilityState={{ disabled, expanded: open }}
455
+ disabled={disabled}
456
+ onPress={enter}
457
+ style={{
458
+ opacity: present ? 0 : 1,
459
+ ...(Platform.OS === 'web' && barFocused && !disabled
460
+ ? { outlineStyle: 'solid', outlineWidth: 3, outlineOffset: 2, outlineColor: theme.colors.secondary }
461
+ : {}),
462
+ }}
463
+ testID={`${testID}-bar`}
464
+ >
465
+ <View
466
+ {...(Platform.OS === 'web' ? { 'aria-hidden': true, inert: true } : {})}
467
+ pointerEvents="none"
468
+ accessible={false}
469
+ accessibilityElementsHidden
470
+ importantForAccessibility="no-hide-descendants"
471
+ >
472
+ <Searchbar
473
+ mode="bar"
474
+ icon={
475
+ onLeadingPress
476
+ ? ({ size }) => (
477
+ <View style={{ width: size, height: size }} testID={`${testID}-leading-placeholder`} />
478
+ )
479
+ : leadingIcon
480
+ }
481
+ editable={false}
482
+ value={value}
483
+ placeholder={placeholder}
484
+ placeholderTextColor={theme.colors.onSurfaceVariant}
485
+ inputStyle={{
486
+ color: theme.colors.onSurface,
487
+ textAlign: barTextAlign === 'center' ? 'center' : rtl ? 'right' : 'left',
488
+ }}
489
+ iconColor={theme.colors.onSurface}
490
+ onChangeText={change}
491
+ right={() => (
492
+ <View
493
+ style={{
494
+ width: trailingContent || trailingActions.length ? trailingWidth : 0,
495
+ }}
496
+ />
497
+ )}
498
+ style={{ backgroundColor: barContainerColor ?? theme.colors.surfaceContainerHigh }}
499
+ />
500
+ </View>
501
+ </SearchTrigger>
502
+ {/* Match the field's 4dp inset and 48dp logical leading target. */}
503
+ {onLeadingPress ? (
504
+ <SearchIconButton
505
+ icon={leadingIcon}
506
+ iconColor={theme.colors.onSurface}
507
+ accessibilityLabel="Abrir navegación"
508
+ disabled={disabled}
509
+ onPress={onLeadingPress}
510
+ style={{
511
+ position: 'absolute',
512
+ top: '50%',
513
+ transform: [{ translateY: -24 }],
514
+ [rtl ? 'right' : 'left']: 4,
515
+ opacity: present ? 0 : 1,
516
+ }}
517
+ testID={`${testID}-leading-action`}
518
+ />
519
+ ) : null}
520
+ {trailingContent || trailingActions.length ? (
521
+ <View
522
+ onLayout={(event) => setTrailingWidth(event.nativeEvent.layout.width)}
523
+ pointerEvents={disabled ? 'none' : 'auto'}
524
+ accessibilityElementsHidden={disabled}
525
+ importantForAccessibility={disabled ? 'no-hide-descendants' : 'auto'}
526
+ style={{
527
+ position: 'absolute',
528
+ [rtl ? 'left' : 'right']: 4,
529
+ top: '50%',
530
+ transform: [{ translateY: -24 }],
531
+ minHeight: 48,
532
+ flexDirection: rtl ? 'row-reverse' : 'row',
533
+ alignItems: 'center',
534
+ opacity: present ? 0 : 1,
535
+ }}
536
+ testID={`${testID}-trailing-content`}
537
+ >
538
+ {trailingActions.map((action) => (
539
+ <View key={action.key} style={{ width: 48, alignItems: 'center' }}>
540
+ <SearchIconButton
541
+ icon={action.icon}
542
+ accessibilityLabel={action.label}
543
+ disabled={disabled || action.disabled}
544
+ onPress={action.onPress}
545
+ testID={action.testID ?? `${testID}-action-${action.key}`}
546
+ />
547
+ </View>
548
+ ))}
549
+ {trailingContent}
550
+ </View>
551
+ ) : null}
552
+ </>
553
+ )}
554
+ </View>
555
+ {present ? (
556
+ <Modal
557
+ accessibilityLabel={placeholder}
558
+ transparent
559
+ animationType="none"
560
+ visible
561
+ onShow={focus}
562
+ onRequestClose={close}
563
+ statusBarTranslucent
564
+ navigationBarTranslucent
565
+ >
566
+ {docked ? (
567
+ <Animated.View key="scrim" pointerEvents="box-none" style={[{ position: 'absolute', inset: 0 }, scrimStyle]}>
568
+ <Pressable
569
+ accessible={false}
570
+ focusable={false}
571
+ {...(Platform.OS === 'web' ? { 'aria-hidden': true, tabIndex: -1 } : {})}
572
+ style={{ position: 'absolute', inset: 0, backgroundColor: theme.colors.scrim }}
573
+ disabled={!open}
574
+ onPress={close}
575
+ testID={`${testID}-outside`}
576
+ />
577
+ </Animated.View>
578
+ ) : null}
579
+ <Animated.View
580
+ key="background"
581
+ pointerEvents="none"
582
+ style={[{ position: 'absolute', backgroundColor: background }, backgroundStyle]}
583
+ />
584
+ {variant === 'contained' ? (
585
+ <Animated.View
586
+ key="capsule"
587
+ pointerEvents="none"
588
+ style={[{ position: 'absolute', backgroundColor: theme.colors.surfaceContainerHigh }, capsuleStyle]}
589
+ testID={`${testID}-capsule`}
590
+ />
591
+ ) : null}
592
+ <Animated.View
593
+ key="content"
594
+ {...(Platform.OS === 'web' ? { 'aria-hidden': !open, inert: !open } : {})}
595
+ pointerEvents={open ? 'auto' : 'none'}
596
+ accessibilityElementsHidden={!open}
597
+ importantForAccessibility={open ? 'auto' : 'no-hide-descendants'}
598
+ accessibilityViewIsModal
599
+ onAccessibilityEscape={close}
600
+ style={[
601
+ docked
602
+ ? {
603
+ position: 'absolute',
604
+ left: panelX,
605
+ top: panelY,
606
+ width: panelWidth,
607
+ height: panelHeight,
608
+ borderRadius: 28,
609
+ overflow: variant === 'divided' ? 'hidden' : 'visible',
610
+ }
611
+ : { flex: 1, paddingTop: insets.top, paddingLeft: insets.left, paddingRight: insets.right },
612
+ { backgroundColor: 'transparent' },
613
+ contentStyle,
614
+ ]}
615
+ testID={`${testID}-view`}
616
+ >
617
+ <SearchInputHeader
618
+ contained={variant === 'contained'}
619
+ animatedStyle={headerStyle}
620
+ style={[
621
+ {
622
+ direction: 'ltr',
623
+ flexDirection: rtl ? 'row-reverse' : 'row',
624
+ alignItems: 'center',
625
+ backgroundColor: variant === 'contained' ? 'transparent' : theme.colors.surfaceContainerHigh,
626
+ ...(variant === 'contained'
627
+ ? {
628
+ marginHorizontal: docked ? 0 : 12,
629
+ marginTop: docked ? 0 : 8,
630
+ marginBottom: docked ? 2 : 8,
631
+ borderRadius: 28,
632
+ }
633
+ : { borderRadius: 0 }),
634
+ },
635
+ ]}
636
+ testID={`${testID}-header`}
637
+ >
638
+ <Searchbar
639
+ ref={input}
640
+ mode={inputMode}
641
+ value={value}
642
+ onChangeText={change}
643
+ placeholder={placeholder}
644
+ accessibilityLabel={placeholder}
645
+ placeholderTextColor={theme.colors.onSurfaceVariant}
646
+ inputStyle={{ color: theme.colors.onSurface }}
647
+ iconColor={leadingColor}
648
+ icon={
649
+ variant === 'contained'
650
+ ? rtl
651
+ ? 'chevron_right'
652
+ : 'chevron_left'
653
+ : rtl
654
+ ? 'arrow_forward'
655
+ : 'arrow_back'
656
+ }
657
+ onIconPress={close}
658
+ searchAccessibilityLabel="Cerrar búsqueda"
659
+ clearAccessibilityLabel="Borrar búsqueda"
660
+ loading={loading}
661
+ editable={open && !disabled}
662
+ onSubmitEditing={submit}
663
+ returnKeyType="search"
664
+ blurOnSubmit={false}
665
+ showDivider={false}
666
+ right={inputActions ? () => (inputMode === 'bar' ? inputActions : null) : undefined}
667
+ style={{
668
+ flex: 1,
669
+ minWidth: 0,
670
+ backgroundColor: variant === 'contained' ? 'transparent' : theme.colors.surfaceContainerHigh,
671
+ borderRadius: variant === 'contained' ? 28 : 0,
672
+ }}
673
+ testID={`${testID}-input`}
674
+ />
675
+ {/* View mode keeps its independent controls in the same row. */}
676
+ {inputMode === 'view' ? inputActions : null}
677
+ </SearchInputHeader>
678
+ {variant === 'divided' ? <Divider style={{ backgroundColor: theme.colors.outline }} /> : null}
679
+ <Animated.View
680
+ style={[
681
+ { flex: 1, minHeight: 0, backgroundColor: background },
682
+ docked && variant === 'contained' ? { borderRadius: 28, overflow: 'hidden', paddingBottom: 4 } : {},
683
+ resultsStyle,
684
+ ]}
685
+ testID={`${testID}-body`}
686
+ >
687
+ <KeyboardAvoidingView
688
+ behavior={Platform.OS === 'ios' ? 'padding' : undefined}
689
+ style={{ flex: 1, backgroundColor: background }}
690
+ >
691
+ {supportingContent ?? (
692
+ <Text
693
+ accessibilityLiveRegion="polite"
694
+ accessibilityRole="header"
695
+ variant="labelLarge"
696
+ style={{ paddingHorizontal: 24, paddingVertical: 12, color: theme.colors.onSurfaceVariant }}
697
+ >
698
+ {loading
699
+ ? 'Buscando…'
700
+ : `${results.length} ${value ? (results.length === 1 ? 'resultado' : 'resultados') : results.length === 1 ? 'sugerencia' : 'sugerencias'}`}
701
+ </Text>
702
+ )}
703
+ {renderResults ? (
704
+ <List.Collection>{renderResults({ containerColor: background })}</List.Collection>
705
+ ) : (
706
+ <List.Collection>
707
+ <FlatList
708
+ accessibilityRole="list"
709
+ accessibilityLabel={value ? 'Resultados de búsqueda' : 'Sugerencias de búsqueda'}
710
+ data={results}
711
+ keyExtractor={(item) => item.key}
712
+ keyboardShouldPersistTaps="handled"
713
+ keyboardDismissMode="on-drag"
714
+ contentContainerStyle={results.length ? { paddingVertical: 8 } : { flexGrow: 1, padding: 24 }}
715
+ renderItem={({ item }) => {
716
+ const row = (
717
+ <List.Item
718
+ title={item.title}
719
+ description={item.description}
720
+ style={{ backgroundColor: background }}
721
+ accessibilityLabel={item.accessibilityLabel ?? item.title}
722
+ disabled={disabled || loading || item.disabled || !onResultPress}
723
+ leading={
724
+ item.icon
725
+ ? ({ color }) => <List.Icon color={color} icon={item.icon!} />
726
+ : undefined
727
+ }
728
+ onPress={() => {
729
+ const current = latest.current;
730
+ const result = current.results.find((entry) => entry.key === item.key);
731
+ if (
732
+ alive.current &&
733
+ current.open &&
734
+ !current.disabled &&
735
+ !current.loading &&
736
+ result &&
737
+ !result.disabled &&
738
+ current.onResultPress
739
+ ) {
740
+ input.current?.blur();
741
+ Keyboard.dismiss();
742
+ current.onResultPress(result);
743
+ if (current.closeOnSelect) close();
744
+ }
745
+ }}
746
+ testID={`${testID}-result-${item.key}`}
747
+ />
748
+ );
749
+ return Platform.OS === 'web' ? <View role="listitem">{row}</View> : row;
750
+ }}
751
+ ListEmptyComponent={
752
+ loading ? undefined : (
753
+ <>
754
+ {emptyContent ?? (
755
+ <Text style={{ color: theme.colors.onSurfaceVariant }}>No hay resultados</Text>
756
+ )}
757
+ </>
758
+ )
759
+ }
760
+ testID={`${testID}-results`}
761
+ {...getScrollIndicatorProps(scrollIndicators)}
762
+ />
763
+ </List.Collection>
764
+ )}
765
+ {footerAvoidsKeyboard ? footer : null}
766
+ </KeyboardAvoidingView>
767
+ {!footerAvoidsKeyboard ? (
768
+ <View
769
+ pointerEvents={Platform.OS === 'android' && keyboardVisible ? 'none' : 'auto'}
770
+ accessibilityElementsHidden={Platform.OS === 'android' && keyboardVisible}
771
+ importantForAccessibility={
772
+ Platform.OS === 'android' && keyboardVisible ? 'no-hide-descendants' : 'auto'
773
+ }
774
+ style={{
775
+ flexShrink: 0,
776
+ backgroundColor: background,
777
+ display: Platform.OS === 'android' && keyboardVisible ? 'none' : 'flex',
778
+ }}
779
+ testID={`${testID}-fixed-footer`}
780
+ >
781
+ {footer}
782
+ </View>
783
+ ) : null}
784
+ </Animated.View>
785
+ </Animated.View>
786
+ </Modal>
787
+ ) : null}
788
+ </>
789
+ );
790
+ }