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,474 @@
1
+ import { topAppBarTokens } from '@mobile-design/tokens';
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // Measurement and motion adapted from AndroidX AppBar.kt, Copyright 2021 The Android Open Source Project.
4
+ // https://github.com/androidx/androidx/blob/d153d87ed76372ece0c99dac837ff07ab845d495/compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/AppBar.kt
5
+ // See ../../LICENSE-Apache-2.0.txt and ../../NOTICE.
6
+ import { useEffect, useLayoutEffect, useState, type ComponentProps, type ReactNode } from 'react';
7
+ import { Platform, View, useWindowDimensions, type ColorValue, type StyleProp, type TextLayoutEvent, type ViewStyle } from 'react-native';
8
+ import { Icon, Text, TouchableRipple, useLocale, useTheme, type Theme } from 'react-native-paper';
9
+ import { GestureDetector } from 'react-native-gesture-handler';
10
+ import Animated, {
11
+ cancelAnimation,
12
+ interpolateColor,
13
+ ReduceMotion,
14
+ useAnimatedProps,
15
+ useAnimatedReaction,
16
+ useAnimatedStyle,
17
+ useSharedValue,
18
+ withSpring,
19
+ type SharedValue,
20
+ } from 'react-native-reanimated';
21
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
22
+ import { scheduleOnUI } from 'react-native-worklets';
23
+ import { IconButton } from './icon-button';
24
+ import {
25
+ appBarCompactTitleAlpha,
26
+ appBarContainerFraction,
27
+ appBarExpandedRow,
28
+ appBarFinite,
29
+ appBarFraction,
30
+ appBarSearchWidth,
31
+ appBarTitleFrame,
32
+ } from './appbar-layout';
33
+ import type { AppBarScrollBehavior } from './appbar-scroll-behavior';
34
+
35
+ export { useAppBarScrollBehavior, type AppBarScrollBehavior, type AppBarScrollMode } from './appbar-scroll-behavior';
36
+
37
+ export type TopAppBarVariant = 'small' | 'medium-flexible' | 'large-flexible';
38
+ export type TopAppBarAction = {
39
+ key: string;
40
+ icon: ComponentProps<typeof Icon>['source'];
41
+ label: string;
42
+ onPress: NonNullable<ComponentProps<typeof TouchableRipple>['onPress']>;
43
+ disabled?: boolean;
44
+ mode?: 'contained' | 'contained-tonal' | 'outlined';
45
+ widthVariant?: 'narrow' | 'default' | 'wide';
46
+ testID?: string;
47
+ };
48
+ export type TopAppBarProps = {
49
+ title: ReactNode;
50
+ /** Tall bars' compact row. Explicit null hides its title and subtitle. */
51
+ collapsedTitle?: ReactNode;
52
+ subtitle?: string;
53
+ textAlign?: 'start' | 'center';
54
+ /** Flexible bars place a logo/image above the headline. */
55
+ image?: ReactNode;
56
+ /** Pass the controlled SearchView entry point for a search app bar. */
57
+ search?: ReactNode;
58
+ variant?: TopAppBarVariant;
59
+ navigationIcon?: ComponentProps<typeof Icon>['source'];
60
+ navigationLabel?: string;
61
+ navigationMode?: TopAppBarAction['mode'];
62
+ navigationWidthVariant?: 'narrow' | 'default' | 'wide';
63
+ onNavigationPress?: () => void;
64
+ /** Optional product logo/avatar; replaces the navigation icon slot. */
65
+ leading?: ReactNode;
66
+ /** Optional trailing element, for example a 32dp avatar in a 48dp target. */
67
+ trailing?: ReactNode;
68
+ actions?: readonly TopAppBarAction[];
69
+ scrollBehavior?: AppBarScrollBehavior;
70
+ /** 0 expanded, 1 collapsed; connect to the actual scroll offset on the UI thread. */
71
+ collapseProgress?: SharedValue<number>;
72
+ scrolled?: boolean;
73
+ statusBarHeight?: number;
74
+ containerColor?: ColorValue;
75
+ /** Continuous UI-thread color, for example a scroll-linked artwork gradient. */
76
+ containerColorSource?: Readonly<Pick<SharedValue<ColorValue>, 'get'>>;
77
+ scrolledContainerColor?: ColorValue;
78
+ /** Search field roles; the child trigger should use a transparent container. */
79
+ searchContainerColor?: ColorValue;
80
+ scrolledSearchContainerColor?: ColorValue;
81
+ style?: StyleProp<ViewStyle>;
82
+ testID?: string;
83
+ };
84
+
85
+ type Measurement = { width: number; height: number };
86
+ type TextMetrics = { height: number; baseline: number };
87
+
88
+ /** Current MD3 layouts; centered text is a configuration of each variant. */
89
+ export function TopAppBar({
90
+ title,
91
+ collapsedTitle = title,
92
+ subtitle,
93
+ textAlign = 'start',
94
+ image,
95
+ search,
96
+ variant = 'small',
97
+ navigationIcon,
98
+ navigationLabel = 'Volver',
99
+ navigationMode,
100
+ navigationWidthVariant,
101
+ onNavigationPress,
102
+ leading,
103
+ trailing,
104
+ actions = [],
105
+ scrollBehavior,
106
+ collapseProgress,
107
+ scrolled = false,
108
+ statusBarHeight,
109
+ containerColor,
110
+ containerColorSource,
111
+ scrolledContainerColor,
112
+ searchContainerColor,
113
+ scrolledSearchContainerColor,
114
+ style,
115
+ testID = 'mobile-top-appbar',
116
+ }: TopAppBarProps) {
117
+ const theme = useTheme<Theme>();
118
+ const insets = useSafeAreaInsets();
119
+ const rtl = useLocale().direction === 'rtl';
120
+ const { fontScale } = useWindowDimensions();
121
+ const top = Math.max(0, appBarFinite(statusBarHeight ?? insets.top));
122
+ const actualVariant = search ? 'small' : variant;
123
+ const tokens = topAppBarTokens[actualVariant];
124
+ const tall = actualVariant !== 'small';
125
+ const centered = textAlign === 'center';
126
+ const hasLeading = leading != null || Boolean(navigationIcon);
127
+ const [headerWidth, setHeaderWidth] = useState(0);
128
+ const [leadingWidth, setLeadingWidth] = useState(0);
129
+ const [trailingWidth, setTrailingWidth] = useState(0);
130
+ const [compactSize, setCompactSize] = useState<Measurement>({ width: 0, height: 0 });
131
+ const [expandedSize, setExpandedSize] = useState<Measurement>({ width: 0, height: 0 });
132
+ const [titleMetrics, setTitleMetrics] = useState<TextMetrics>({ height: 0, baseline: 0 });
133
+ const [subtitleMetrics, setSubtitleMetrics] = useState<TextMetrics>({ height: 0, baseline: 0 });
134
+ const [searchHeight, setSearchHeight] = useState(56);
135
+ const compactHasContent = !(tall && collapsedTitle === null);
136
+ const compactFallback =
137
+ !tall && image
138
+ ? 48
139
+ : (theme.fonts.titleLarge.lineHeight ?? 28) * fontScale +
140
+ (subtitle ? (theme.fonts.labelMedium.lineHeight ?? 16) * fontScale : 0);
141
+ const compactHeight = Math.max(64, search ? searchHeight + 8 : compactHasContent ? compactSize.height || compactFallback : 0);
142
+ const baseHeight = 'subtitleHeight' in tokens && subtitle ? tokens.subtitleHeight : tokens.height;
143
+ const expandedContentHeight =
144
+ expandedSize.height ||
145
+ (theme.fonts[tokens.title].lineHeight ?? 36) * fontScale +
146
+ (subtitle ? (theme.fonts[tokens.subtitle].lineHeight ?? 20) * fontScale : 0);
147
+ const lastText = subtitle ? subtitleMetrics : titleMetrics;
148
+ const lastBaseline = lastText.height > 0 ? expandedContentHeight - lastText.height + lastText.baseline : expandedContentHeight - 12;
149
+ const expandedRow = appBarExpandedRow(
150
+ baseHeight - 64,
151
+ expandedContentHeight,
152
+ lastBaseline,
153
+ actualVariant === 'large-flexible' ? 28 : 24
154
+ );
155
+ const expandedHeight = tall ? compactHeight + expandedRow.height : compactHeight;
156
+ const measuredLeadingWidth = hasLeading ? leadingWidth || (navigationWidthVariant === 'wide' ? 52 : 48) : 0;
157
+ const actionWidth =
158
+ actions.reduce((sum, action) => sum + (action.widthVariant === 'wide' ? 52 : 48), 0) + (trailing != null ? trailingWidth || 48 : 0);
159
+ const searchWidth = appBarSearchWidth(headerWidth - insets.left - insets.right - measuredLeadingWidth - actionWidth - 24);
160
+ const titleFrame = appBarTitleFrame(
161
+ headerWidth,
162
+ insets.left,
163
+ insets.right,
164
+ measuredLeadingWidth,
165
+ actionWidth,
166
+ hasLeading,
167
+ rtl,
168
+ centered,
169
+ compactSize.width
170
+ );
171
+ const progress = scrollBehavior?.collapseProgress ?? collapseProgress;
172
+ const behaviorHeightOffset = scrollBehavior?.heightOffset;
173
+ const behaviorContentOffset = scrollBehavior?._contentOffset;
174
+ const behaviorMode = scrollBehavior?._mode;
175
+ const colorProgress = useSharedValue(Number(scrolled));
176
+ const flatColor = containerColor ?? theme.colors.surface;
177
+ const onScrollColor = scrolledContainerColor ?? theme.colors.surfaceContainer;
178
+ const fieldColor = searchContainerColor ?? theme.colors.surfaceContainer;
179
+ const onScrollFieldColor = scrolledSearchContainerColor ?? theme.colors.surfaceContainerHighest;
180
+ const reduced = theme.animation.scale === 0;
181
+ const spring = theme.motion.spring.default.effects;
182
+ const colorConfig = {
183
+ stiffness: spring.stiffness,
184
+ damping: 2 * spring.damping * Math.sqrt(spring.stiffness),
185
+ mass: 1,
186
+ reduceMotion: ReduceMotion.Never,
187
+ };
188
+ const scrollActive = () => {
189
+ 'worklet';
190
+ return (
191
+ scrolled ||
192
+ (behaviorContentOffset
193
+ ? appBarFinite(behaviorContentOffset.get()) > 0.01
194
+ : progress
195
+ ? appBarFraction(progress.get()) > 0.01
196
+ : false)
197
+ );
198
+ };
199
+ useLayoutEffect(() => {
200
+ scrollBehavior?._setLayout(expandedHeight, compactHeight, top);
201
+ }, [compactHeight, expandedHeight, scrollBehavior, top]);
202
+ useEffect(() => {
203
+ scheduleOnUI(() => {
204
+ 'worklet';
205
+ cancelAnimation(colorProgress);
206
+ const target = Number(scrollActive());
207
+ colorProgress.set(reduced ? target : withSpring(target, colorConfig));
208
+ });
209
+ return () => {
210
+ scheduleOnUI(() => {
211
+ 'worklet';
212
+ cancelAnimation(colorProgress);
213
+ });
214
+ };
215
+ }, [colorProgress, progress, reduced, scrolled, scrollBehavior, spring.damping, spring.stiffness]);
216
+ useAnimatedReaction(
217
+ scrollActive,
218
+ (active, previous) => {
219
+ if (active === previous) return;
220
+ colorProgress.set(reduced ? Number(active) : withSpring(Number(active), colorConfig));
221
+ },
222
+ [behaviorContentOffset, progress, scrolled, reduced, spring.damping, spring.stiffness, colorProgress]
223
+ );
224
+ const bounds = useAnimatedStyle(() => {
225
+ // Read both shared values directly: web mappers cannot discover a
226
+ // subscription hidden inside another captured worklet function.
227
+ const containerFraction =
228
+ tall && progress && !scrolled && (!behaviorMode || behaviorMode.get() !== 'pinned')
229
+ ? appBarContainerFraction(progress.get())
230
+ : appBarFraction(colorProgress.get());
231
+ const fraction = appBarFraction(progress?.get() ?? 0);
232
+ const height = Math.max(
233
+ 0,
234
+ behaviorHeightOffset
235
+ ? top + expandedHeight + appBarFinite(behaviorHeightOffset.get())
236
+ : top + expandedHeight + (compactHeight - expandedHeight) * fraction
237
+ );
238
+ return {
239
+ height,
240
+ // Overflow clips the pixels but leaves the hidden actions in the browser's tab order.
241
+ ...(Platform.OS === 'web' && behaviorHeightOffset
242
+ ? { visibility: height === 0 ? ('hidden' as const) : ('visible' as const) }
243
+ : {}),
244
+ backgroundColor: containerColorSource
245
+ ? containerColorSource.get()
246
+ : typeof flatColor === 'string' && typeof onScrollColor === 'string'
247
+ ? interpolateColor(containerFraction, [0, 1], [flatColor, onScrollColor], 'LAB')
248
+ : containerFraction > 0.01
249
+ ? onScrollColor
250
+ : flatColor,
251
+ };
252
+ });
253
+ const body = useAnimatedStyle(() => {
254
+ const fraction = appBarFraction(progress?.get() ?? 0);
255
+ const hidden = behaviorHeightOffset ? Math.max(0, -appBarFinite(behaviorHeightOffset.get()) - (expandedHeight - compactHeight)) : 0;
256
+ return {
257
+ height: top + expandedHeight + (compactHeight - expandedHeight) * fraction,
258
+ transform: [{ translateY: -hidden }],
259
+ };
260
+ });
261
+ const compact = useAnimatedStyle(() => ({ opacity: tall ? appBarCompactTitleAlpha(progress?.get() ?? 0) : 1 }));
262
+ const expanded = useAnimatedStyle(() => ({ opacity: 1 - appBarFraction(progress?.get() ?? 0) }));
263
+ const compactAccessibility = useAnimatedProps(() => ({
264
+ accessibilityElementsHidden: tall && appBarFraction(progress?.get() ?? 0) < 0.5,
265
+ ...(Platform.OS === 'web' ? { 'aria-hidden': tall && appBarFraction(progress?.get() ?? 0) < 0.5 } : {}),
266
+ importantForAccessibility:
267
+ tall && appBarFraction(progress?.get() ?? 0) < 0.5 ? ('no-hide-descendants' as const) : ('auto' as const),
268
+ pointerEvents: tall && appBarFraction(progress?.get() ?? 0) < 0.5 ? ('none' as const) : ('auto' as const),
269
+ }));
270
+ const expandedAccessibility = useAnimatedProps(() => ({
271
+ accessibilityElementsHidden: appBarFraction(progress?.get() ?? 0) >= 0.5,
272
+ ...(Platform.OS === 'web' ? { 'aria-hidden': appBarFraction(progress?.get() ?? 0) >= 0.5 } : {}),
273
+ importantForAccessibility: appBarFraction(progress?.get() ?? 0) >= 0.5 ? ('no-hide-descendants' as const) : ('auto' as const),
274
+ pointerEvents: appBarFraction(progress?.get() ?? 0) >= 0.5 ? ('none' as const) : ('auto' as const),
275
+ }));
276
+ const searchBackground = useAnimatedStyle(() => {
277
+ const fraction = appBarFraction(colorProgress.get());
278
+ return {
279
+ backgroundColor:
280
+ typeof fieldColor === 'string' && typeof onScrollFieldColor === 'string'
281
+ ? interpolateColor(fraction, [0, 1], [fieldColor, onScrollFieldColor], 'LAB')
282
+ : fraction > 0.01
283
+ ? onScrollFieldColor
284
+ : fieldColor,
285
+ };
286
+ });
287
+ const measureContent = (expanded: boolean, size: Measurement) => {
288
+ const setter = expanded ? setExpandedSize : setCompactSize;
289
+ setter((previous) => (previous.width === size.width && previous.height === size.height ? previous : size));
290
+ };
291
+ const measureText = (event: TextLayoutEvent, subtitle: boolean) => {
292
+ const lines = event.nativeEvent.lines.slice(0, subtitle ? 1 : 2);
293
+ const last = lines[lines.length - 1];
294
+ if (!last) return;
295
+ const next = { height: last.y + last.height, baseline: last.y + last.ascender };
296
+ (subtitle ? setSubtitleMetrics : setTitleMetrics)((previous) =>
297
+ previous.height === next.height && previous.baseline === next.baseline ? previous : next
298
+ );
299
+ };
300
+ const titleContent = (font: keyof Theme['fonts'], isExpanded = false) => {
301
+ const text = isExpanded || !tall ? title : collapsedTitle;
302
+ return (
303
+ <View
304
+ onLayout={(event) => measureContent(isExpanded, event.nativeEvent.layout)}
305
+ style={{
306
+ minWidth: 0,
307
+ maxWidth: '100%',
308
+ alignItems: centered ? 'center' : rtl ? 'flex-end' : 'flex-start',
309
+ alignSelf: centered ? 'center' : rtl ? 'flex-end' : 'flex-start',
310
+ ...(!isExpanded && centered ? { transform: [{ translateX: titleFrame.translateX }] } : {}),
311
+ }}
312
+ testID={`${testID}-${isExpanded ? 'expanded' : 'compact'}-content`}
313
+ >
314
+ {isExpanded && image ? <View style={{ marginBottom: 8 }}>{image}</View> : null}
315
+ {!isExpanded && !tall && image ? (
316
+ <View style={{ maxHeight: 48 }}>{image}</View>
317
+ ) : typeof text === 'string' || typeof text === 'number' ? (
318
+ <Text
319
+ accessibilityRole="header"
320
+ numberOfLines={isExpanded ? 2 : 1}
321
+ ellipsizeMode={isExpanded ? 'clip' : 'tail'}
322
+ onTextLayout={isExpanded ? (event) => measureText(event, false) : undefined}
323
+ style={[
324
+ theme.fonts[font],
325
+ { color: theme.colors.onSurface, textAlign: centered ? 'center' : rtl ? 'right' : 'left' },
326
+ ]}
327
+ >
328
+ {text}
329
+ </Text>
330
+ ) : (
331
+ text
332
+ )}
333
+ {subtitle && (isExpanded || compactHasContent) && (tall || !image) ? (
334
+ <Text
335
+ numberOfLines={1}
336
+ onTextLayout={isExpanded ? (event) => measureText(event, true) : undefined}
337
+ style={[
338
+ theme.fonts[isExpanded ? tokens.subtitle : 'labelMedium'],
339
+ { color: theme.colors.onSurfaceVariant, textAlign: centered ? 'center' : rtl ? 'right' : 'left' },
340
+ ]}
341
+ >
342
+ {subtitle}
343
+ </Text>
344
+ ) : null}
345
+ </View>
346
+ );
347
+ };
348
+ const surface = (
349
+ <Animated.View
350
+ collapsable={false}
351
+ style={[
352
+ { width: '100%', overflow: 'hidden', borderRadius: 0, ...(Platform.OS === 'web' ? { direction: 'ltr' as const } : {}) },
353
+ bounds,
354
+ style,
355
+ ]}
356
+ testID={testID}
357
+ >
358
+ <Animated.View style={[{ paddingTop: top }, body]}>
359
+ <View
360
+ onLayout={(event) => setHeaderWidth(event.nativeEvent.layout.width)}
361
+ style={{
362
+ height: compactHeight,
363
+ flexDirection: rtl ? 'row-reverse' : 'row',
364
+ alignItems: 'center',
365
+ paddingLeft: 4 + insets.left,
366
+ paddingRight: 4 + insets.right,
367
+ }}
368
+ testID={`${testID}-row`}
369
+ >
370
+ {hasLeading ? (
371
+ <View
372
+ onLayout={(event) => setLeadingWidth(event.nativeEvent.layout.width)}
373
+ style={{ minWidth: 48, height: 48, alignItems: 'center', justifyContent: 'center' }}
374
+ testID={`${testID}-leading-slot`}
375
+ >
376
+ {leading ?? (
377
+ <IconButton
378
+ icon={navigationIcon!}
379
+ mode={navigationMode}
380
+ widthVariant={navigationWidthVariant}
381
+ iconColor={navigationMode ? undefined : theme.colors.onSurface}
382
+ accessibilityLabel={navigationLabel}
383
+ disabled={!onNavigationPress}
384
+ onPress={onNavigationPress}
385
+ testID={`${testID}-navigation`}
386
+ />
387
+ )}
388
+ </View>
389
+ ) : null}
390
+ {search ? (
391
+ <View style={{ flex: 1, paddingHorizontal: 8, alignItems: 'center' }}>
392
+ <Animated.View
393
+ onLayout={(event) => setSearchHeight(event.nativeEvent.layout.height)}
394
+ style={[
395
+ { width: headerWidth > 0 ? searchWidth : '100%', minHeight: 56, borderRadius: 28 },
396
+ searchBackground,
397
+ ]}
398
+ testID={`${testID}-search-container`}
399
+ >
400
+ {search}
401
+ </Animated.View>
402
+ </View>
403
+ ) : (
404
+ <>
405
+ <Animated.View
406
+ animatedProps={compactAccessibility}
407
+ style={[
408
+ {
409
+ position: 'absolute',
410
+ left: titleFrame.left,
411
+ width: titleFrame.width,
412
+ top: 0,
413
+ bottom: 0,
414
+ justifyContent: 'center',
415
+ minWidth: 0,
416
+ },
417
+ compact,
418
+ ]}
419
+ testID={`${testID}-compact`}
420
+ >
421
+ {titleContent('titleLarge')}
422
+ </Animated.View>
423
+ <View style={{ flex: 1 }} />
424
+ </>
425
+ )}
426
+ {actions.map((action) => (
427
+ <View key={action.key} style={{ minWidth: 48, height: 48, alignItems: 'center', justifyContent: 'center' }}>
428
+ <IconButton
429
+ icon={action.icon}
430
+ mode={action.mode}
431
+ widthVariant={action.widthVariant}
432
+ iconColor={action.mode ? undefined : theme.colors.onSurfaceVariant}
433
+ accessibilityLabel={action.label}
434
+ disabled={action.disabled}
435
+ onPress={action.onPress}
436
+ testID={action.testID ?? `${testID}-${action.key}`}
437
+ />
438
+ </View>
439
+ ))}
440
+ {trailing != null ? (
441
+ <View
442
+ onLayout={(event) => setTrailingWidth(event.nativeEvent.layout.width)}
443
+ style={{ minWidth: 48, minHeight: 48, alignItems: 'center', justifyContent: 'center' }}
444
+ testID={`${testID}-trailing-slot`}
445
+ >
446
+ {trailing}
447
+ </View>
448
+ ) : null}
449
+ </View>
450
+ {tall ? (
451
+ <Animated.View
452
+ animatedProps={expandedAccessibility}
453
+ style={[
454
+ {
455
+ position: 'absolute',
456
+ top: top + compactHeight,
457
+ bottom: 0,
458
+ left: 16 + insets.left,
459
+ right: 16 + insets.right,
460
+ justifyContent: 'flex-end',
461
+ paddingBottom: expandedRow.bottomPadding,
462
+ },
463
+ expanded,
464
+ ]}
465
+ testID={`${testID}-expanded`}
466
+ >
467
+ {titleContent(tokens.title, true)}
468
+ </Animated.View>
469
+ ) : null}
470
+ </Animated.View>
471
+ </Animated.View>
472
+ );
473
+ return scrollBehavior?._dragGesture ? <GestureDetector gesture={scrollBehavior._dragGesture}>{surface}</GestureDetector> : surface;
474
+ }
@@ -0,0 +1,135 @@
1
+ import { TouchableRipple } from '../ripple';
2
+ import { useEffect, useState, type ComponentProps, type ReactNode } from 'react';
3
+ import { StyleSheet, View, type StyleProp, type ViewStyle } from 'react-native';
4
+ import { Avatar as PaperAvatar } from 'react-native-paper';
5
+ import { useMobileTheme } from '../core';
6
+ import { withAlpha } from '../color';
7
+
8
+ export type AvatarButtonProps = Omit<
9
+ ComponentProps<typeof TouchableRipple>,
10
+ 'children' | 'onPress' | 'accessibilityLabel' | 'style' | 'borderless' | 'background'
11
+ > & {
12
+ children: ReactNode;
13
+ onPress: NonNullable<ComponentProps<typeof TouchableRipple>['onPress']>;
14
+ accessibilityLabel: string;
15
+ style?: StyleProp<ViewStyle>;
16
+ };
17
+
18
+ /** Interactive avatar target. Visual Avatar.Icon/Image/Text remain noninteractive. */
19
+ export function AvatarButton({
20
+ children,
21
+ onPress,
22
+ accessibilityLabel,
23
+ disabled = false,
24
+ style,
25
+ theme: override,
26
+ rippleColor,
27
+ accessibilityState,
28
+ onPressIn,
29
+ onPressOut,
30
+ onHoverIn,
31
+ onHoverOut,
32
+ onFocus,
33
+ onBlur,
34
+ testID = 'mobile-avatar-button',
35
+ ...props
36
+ }: AvatarButtonProps) {
37
+ const theme = useMobileTheme(override);
38
+ const [hovered, setHovered] = useState(false);
39
+ const [focused, setFocused] = useState(false);
40
+ const [pressed, setPressed] = useState(false);
41
+ useEffect(() => {
42
+ if (disabled) {
43
+ setHovered(false);
44
+ setFocused(false);
45
+ setPressed(false);
46
+ }
47
+ }, [disabled]);
48
+ return (
49
+ <TouchableRipple
50
+ {...props}
51
+ theme={theme}
52
+ accessibilityRole="button"
53
+ accessibilityLabel={accessibilityLabel}
54
+ accessibilityState={{ ...accessibilityState, disabled }}
55
+ disabled={disabled}
56
+ borderless={false}
57
+ rippleColor={
58
+ rippleColor ??
59
+ (typeof theme.colors.onSurface === 'string' ? withAlpha(theme.colors.onSurface, 0.1) : theme.colors.stateLayerPressed)
60
+ }
61
+ onPress={(event) => {
62
+ if (!disabled) onPress(event);
63
+ }}
64
+ onPressIn={(event) => {
65
+ if (!disabled) {
66
+ setPressed(true);
67
+ onPressIn?.(event);
68
+ }
69
+ }}
70
+ onPressOut={(event) => {
71
+ setPressed(false);
72
+ onPressOut?.(event);
73
+ }}
74
+ onHoverIn={(event) => {
75
+ if (!disabled) {
76
+ setHovered(true);
77
+ onHoverIn?.(event);
78
+ }
79
+ }}
80
+ onHoverOut={(event) => {
81
+ setHovered(false);
82
+ onHoverOut?.(event);
83
+ }}
84
+ onFocus={(event) => {
85
+ if (!disabled) {
86
+ setFocused(true);
87
+ onFocus?.(event);
88
+ }
89
+ }}
90
+ onBlur={(event) => {
91
+ setFocused(false);
92
+ setPressed(false);
93
+ onBlur?.(event);
94
+ }}
95
+ // The same circular host clips native ripple and owns the complete target.
96
+ // An explicit background also prevents Paper's web hover from stacking.
97
+ style={[
98
+ { backgroundColor: 'transparent' },
99
+ style,
100
+ {
101
+ width: 48,
102
+ height: 48,
103
+ borderRadius: 24,
104
+ overflow: 'hidden',
105
+ alignItems: 'center',
106
+ justifyContent: 'center',
107
+ opacity: disabled ? 0.38 : 1,
108
+ },
109
+ ]}
110
+ testID={testID}
111
+ >
112
+ <View
113
+ pointerEvents="none"
114
+ accessible={false}
115
+ accessibilityElementsHidden
116
+ importantForAccessibility="no-hide-descendants"
117
+ style={{ flex: 1, alignSelf: 'stretch', alignItems: 'center', justifyContent: 'center' }}
118
+ >
119
+ {children}
120
+ {!disabled && !pressed && (hovered || focused) ? (
121
+ <View
122
+ pointerEvents="none"
123
+ style={[
124
+ StyleSheet.absoluteFill,
125
+ { borderRadius: 24, backgroundColor: theme.colors.onSurface, opacity: focused ? 0.1 : 0.08 },
126
+ ]}
127
+ testID={`${testID}-state-layer`}
128
+ />
129
+ ) : null}
130
+ </View>
131
+ </TouchableRipple>
132
+ );
133
+ }
134
+
135
+ export const Avatar = { ...PaperAvatar, Button: AvatarButton };
@@ -0,0 +1,13 @@
1
+ import { forwardRef } from 'react';
2
+ import { BottomSheetTextInput } from './bottom-sheet-text-input';
3
+ import { TextField, type TextFieldHandle, type TextFieldProps } from './text-field';
4
+
5
+ export type BottomSheetTextFieldProps = Omit<TextFieldProps, 'inputComponent'>;
6
+
7
+ // Gorhom forwards the native input handle; its published ref still uses RN's old component alias.
8
+ const CoordinatedInput = BottomSheetTextInput as NonNullable<TextFieldProps['inputComponent']>;
9
+
10
+ /** MD3 field chrome with Gorhom's keyboard and focus coordination inside a sheet. */
11
+ export const BottomSheetTextField = forwardRef<TextFieldHandle, BottomSheetTextFieldProps>(function BottomSheetTextField(props, ref) {
12
+ return <TextField {...props} ref={ref} inputComponent={CoordinatedInput} />;
13
+ });
@@ -0,0 +1,2 @@
1
+ /** Native keyboard coordination belongs to the sheet's gesture motor. */
2
+ export { BottomSheetTextInput } from '@gorhom/bottom-sheet';
@@ -0,0 +1,2 @@
1
+ /** The browser coordinates its own keyboard and focus; native input state is unavailable. */
2
+ export { TextInput as BottomSheetTextInput } from 'react-native';