@wasto/cms-components 1.5.10 → 1.5.12

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 (101) hide show
  1. package/README.md +47 -47
  2. package/dist/index.d.mts +181 -51
  3. package/dist/index.d.ts +181 -51
  4. package/dist/index.js +3614 -3015
  5. package/dist/index.mjs +3021 -2418
  6. package/package.json +12 -2
  7. package/src/components/announcement-modal/AnnouncementModal.tsx +183 -183
  8. package/src/components/article/Article.tsx +21 -21
  9. package/src/components/article/ArticleCard.tsx +81 -81
  10. package/src/components/article/ArticleExcerpts.tsx +80 -80
  11. package/src/components/article/ArticleList.tsx +114 -114
  12. package/src/components/article/ArticleMarkdown.tsx +170 -170
  13. package/src/components/article/ArticleReaderModal.tsx +93 -93
  14. package/src/components/article/ArticleSingle.tsx +57 -57
  15. package/src/components/bottom-tab/BottomTab.tsx +392 -392
  16. package/src/components/button/Button.tsx +154 -154
  17. package/src/components/challenge/Badges.tsx +84 -84
  18. package/src/components/challenge/BadgesModal.tsx +166 -166
  19. package/src/components/challenge/Challenge.tsx +380 -380
  20. package/src/components/challenge/ChallengeModal.tsx +231 -231
  21. package/src/components/challenge/ChallengeVignette.tsx +249 -249
  22. package/src/components/challenge/ChallengesModal.tsx +243 -243
  23. package/src/components/challenge/QuizModal.tsx +381 -381
  24. package/src/components/challenge/ResultModal.tsx +144 -144
  25. package/src/components/chat/Chat.tsx +928 -928
  26. package/src/components/collection-calendar/CollectionCalendar.tsx +274 -274
  27. package/src/components/columns/Columns.tsx +33 -33
  28. package/src/components/consignes-modal/ConsignesModal.tsx +267 -267
  29. package/src/components/content-inset/ContentInset.tsx +33 -33
  30. package/src/components/header/Header.tsx +415 -391
  31. package/src/components/image/Image.tsx +15 -15
  32. package/src/components/image/ImageFrame.tsx +102 -102
  33. package/src/components/image/ImageMedia.tsx +31 -31
  34. package/src/components/image/ImageUrl.tsx +30 -30
  35. package/src/components/locations-map/LocationSheet.tsx +417 -417
  36. package/src/components/locations-map/LocationsMap.native.tsx +260 -260
  37. package/src/components/locations-map/LocationsMap.tsx +13 -13
  38. package/src/components/locations-map/LocationsMap.web.tsx +10 -10
  39. package/src/components/locations-map/LocationsMapShell.tsx +546 -527
  40. package/src/components/locations-map/LocationsMapView.tsx +108 -108
  41. package/src/components/locations-map/LocationsMapView.web.tsx +331 -331
  42. package/src/components/nav-button/NavButton.tsx +59 -59
  43. package/src/components/next-collection/NextCollection.tsx +636 -621
  44. package/src/components/notifications/NotificationsScreen.tsx +247 -247
  45. package/src/components/page/Page.tsx +102 -64
  46. package/src/components/parapraph/Paragraph.tsx +67 -67
  47. package/src/components/profile/ProfileScreen.tsx +236 -236
  48. package/src/components/push/PushTokenRegistrar.tsx +47 -0
  49. package/src/components/recycling-info/RecyclingInfo.tsx +189 -189
  50. package/src/components/safe-area/OptionalSafeAreaProvider.tsx +17 -17
  51. package/src/components/search/Search.tsx +320 -320
  52. package/src/components/select-street-modal/SelectStreetModal.tsx +475 -475
  53. package/src/components/title/Title.tsx +100 -100
  54. package/src/components/vision/Vision.tsx +447 -447
  55. package/src/components/vision/VisionActionCard.tsx +117 -117
  56. package/src/components/vision/VisionCapture.tsx +30 -30
  57. package/src/components/vision/VisionTapOverlay.tsx +122 -122
  58. package/src/contexts/AnnouncementsContext.tsx +171 -171
  59. package/src/contexts/AppDataContext.tsx +458 -0
  60. package/src/contexts/ChallengesContext.tsx +182 -182
  61. package/src/contexts/HeaderConfigContext.tsx +29 -0
  62. package/src/contexts/LocalContext.tsx +227 -227
  63. package/src/contexts/ThemeContext.tsx +37 -37
  64. package/src/contexts/WastoContext.tsx +132 -127
  65. package/src/helpers/blogPost.ts +72 -72
  66. package/src/helpers/generateQuizQuestions.ts +247 -247
  67. package/src/helpers/getContrastColor.ts +18 -18
  68. package/src/helpers/haptics.ts +20 -20
  69. package/src/helpers/hoursSchedule.ts +230 -230
  70. package/src/helpers/htmlContentToMarkdown.ts +114 -114
  71. package/src/helpers/layout.ts +54 -54
  72. package/src/helpers/loadLinearGradient.ts +22 -22
  73. package/src/helpers/mapLocations.ts +170 -0
  74. package/src/helpers/maquetteTheme.ts +76 -76
  75. package/src/helpers/markdownUnderlinePlugin.ts +32 -32
  76. package/src/helpers/nextCollection.ts +122 -0
  77. package/src/helpers/normalizeWasteTypeRecyclingInfo.ts +80 -80
  78. package/src/helpers/publicMediaUrl.ts +8 -8
  79. package/src/helpers/resolveApiAssetUrl.ts +21 -21
  80. package/src/helpers/systemRoutes.ts +7 -7
  81. package/src/helpers/themeStyles.ts +114 -114
  82. package/src/helpers/ttlCache.ts +41 -0
  83. package/src/helpers/useSafeAreaPadding.ts +14 -14
  84. package/src/hooks/useBadges.ts +100 -100
  85. package/src/hooks/useBlogPosts.ts +109 -105
  86. package/src/hooks/useChallenges.ts +110 -110
  87. package/src/hooks/useCities.ts +56 -56
  88. package/src/hooks/useCityAnnouncements.ts +118 -118
  89. package/src/hooks/useCollectionCalendar.ts +421 -421
  90. package/src/hooks/useColumns.ts +19 -19
  91. package/src/hooks/useConsignes.ts +62 -62
  92. package/src/hooks/useLocations.ts +120 -248
  93. package/src/hooks/useNextCollection.ts +163 -238
  94. package/src/hooks/useRecyclingInfo.ts +90 -90
  95. package/src/hooks/useWastoClient.ts +16 -16
  96. package/src/index.ts +161 -142
  97. package/src/navigation/NavigationContext.tsx +56 -56
  98. package/src/push/registerExpoPushToken.ts +133 -0
  99. package/src/sentry/initSentry.ts +120 -120
  100. package/src/types/Theme.ts +72 -72
  101. package/src/types/css-modules.d.ts +1 -1
@@ -1,392 +1,392 @@
1
- import {
2
- useCallback,
3
- useLayoutEffect,
4
- useRef,
5
- useState,
6
- type MutableRefObject,
7
- type ReactNode,
8
- } from "react";
9
- import type { BottomTabBarProps } from "@react-navigation/bottom-tabs";
10
- import { Pressable, StyleSheet, View } from "react-native";
11
- import { Gesture, GestureDetector, GestureHandlerRootView } from "react-native-gesture-handler";
12
- import Animated, {
13
- cancelAnimation,
14
- Extrapolation,
15
- interpolate,
16
- runOnJS,
17
- type SharedValue,
18
- useAnimatedStyle,
19
- useSharedValue,
20
- withSpring,
21
- } from "react-native-reanimated";
22
- import { useSafeAreaInsets } from "react-native-safe-area-context";
23
- import { useTheme } from "../../contexts/ThemeContext";
24
- import { Theme } from "../../types/Theme";
25
- import { resolveTheme } from "../../helpers/themeStyles";
26
- import { hapticSelection } from "../../helpers/haptics";
27
-
28
- export type BottomTabProps = BottomTabBarProps;
29
-
30
- /** Maquette Frame 25: 64×44 squircle behind the active icon. */
31
- const PILL_W = 64;
32
- const PILL_H = 44;
33
- const ICON_SIZE = 24;
34
- const BAR_PAD_X = 24;
35
- const PILL_TOP = 12;
36
- const SPRING = { damping: 18, stiffness: 220, mass: 0.85 };
37
- /** Au-delà, un flick ne change qu’une tab (évite de sauter à la dernière). */
38
- const FLING_VX = 650;
39
-
40
- function xForIndex(index: number, tabW: number, padX: number) {
41
- "worklet";
42
- return padX + index * tabW + (tabW - PILL_W) / 2;
43
- }
44
-
45
- function nearestIndex(x: number, tabW: number, padX: number, count: number) {
46
- "worklet";
47
- if (tabW <= 0 || count <= 0) return 0;
48
- const i = Math.round((x - padX - (tabW - PILL_W) / 2) / tabW);
49
- return Math.max(0, Math.min(count - 1, i));
50
- }
51
-
52
- function tabProgress(pillX: number, index: number, tabW: number) {
53
- "worklet";
54
- if (tabW <= 0) return 0;
55
- const tabCenter = index * tabW + tabW / 2;
56
- const pillCenter = pillX + PILL_W / 2;
57
- return interpolate(
58
- Math.abs(pillCenter - tabCenter),
59
- [0, tabW * 0.52],
60
- [1, 0],
61
- Extrapolation.CLAMP,
62
- );
63
- }
64
-
65
- function rubberband(overshoot: number, dim: number) {
66
- "worklet";
67
- const c = 0.55;
68
- return (1 - 1 / (overshoot * c / Math.max(dim, 1) + 1)) * dim;
69
- }
70
-
71
- function TabItem({
72
- index,
73
- label,
74
- icon,
75
- onPress,
76
- selected,
77
- pillX,
78
- tabW,
79
- primary,
80
- muted,
81
- onPrimary,
82
- dragging,
83
- }: {
84
- index: number;
85
- label: string;
86
- icon: (color: string) => ReactNode;
87
- onPress: () => void;
88
- selected: boolean;
89
- pillX: SharedValue<number>;
90
- tabW: number;
91
- primary: string;
92
- muted: string;
93
- onPrimary: string;
94
- dragging: MutableRefObject<boolean>;
95
- }) {
96
- const idleIconStyle = useAnimatedStyle(() => ({
97
- opacity: 1 - tabProgress(pillX.value, index, tabW),
98
- }), [index, tabW]);
99
-
100
- const activeIconStyle = useAnimatedStyle(() => ({
101
- opacity: tabProgress(pillX.value, index, tabW),
102
- }), [index, tabW]);
103
-
104
- const idleLabelStyle = useAnimatedStyle(() => ({
105
- opacity: 1 - tabProgress(pillX.value, index, tabW),
106
- }), [index, tabW]);
107
-
108
- const activeLabelStyle = useAnimatedStyle(() => ({
109
- opacity: tabProgress(pillX.value, index, tabW),
110
- }), [index, tabW]);
111
-
112
- return (
113
- <Pressable
114
- onPress={() => {
115
- if (dragging.current) return;
116
- onPress();
117
- }}
118
- style={styles.tabItem}
119
- accessibilityRole="tab"
120
- accessibilityState={{ selected }}
121
- accessibilityLabel={label}
122
- >
123
- <View style={styles.iconSlot}>
124
- <Animated.View style={[styles.iconLayer, idleIconStyle]}>
125
- {icon(muted)}
126
- </Animated.View>
127
- <Animated.View style={[styles.iconLayer, activeIconStyle]}>
128
- {icon(onPrimary)}
129
- </Animated.View>
130
- </View>
131
- <View style={styles.labelSlot}>
132
- <Animated.Text
133
- style={[styles.label, styles.labelIdle, { color: muted }, idleLabelStyle]}
134
- numberOfLines={1}
135
- >
136
- {label}
137
- </Animated.Text>
138
- <Animated.Text
139
- style={[styles.label, styles.labelActive, { color: primary }, activeLabelStyle]}
140
- numberOfLines={1}
141
- >
142
- {label}
143
- </Animated.Text>
144
- </View>
145
- </Pressable>
146
- );
147
- }
148
-
149
- export function BottomTab({
150
- state,
151
- descriptors,
152
- navigation,
153
- }: BottomTabProps): ReactNode {
154
- const { theme } = useTheme();
155
- const t = resolveTheme(theme);
156
- const insets = useSafeAreaInsets();
157
- const themedStyles = createThemedStyles(theme);
158
- const muted = t.colors.muted ?? theme.colors.onSurface;
159
- const count = state.routes.length;
160
-
161
- const [rowWidth, setRowWidth] = useState(0);
162
- const tabW = count > 0 && rowWidth > 0 ? rowWidth / count : 0;
163
- const pillX = useSharedValue(0);
164
- const tabWSV = useSharedValue(0);
165
- const countSV = useSharedValue(count);
166
- const dragStartX = useSharedValue(0);
167
- const dragStartIndex = useSharedValue(state.index);
168
- const pressed = useSharedValue(0);
169
- const lastTick = useSharedValue(state.index);
170
- const dragging = useRef(false);
171
- const routesRef = useRef(state.routes);
172
- const indexRef = useRef(state.index);
173
- routesRef.current = state.routes;
174
- indexRef.current = state.index;
175
- countSV.value = count;
176
-
177
- useLayoutEffect(() => {
178
- tabWSV.value = tabW;
179
- if (tabW <= 0) return;
180
- pillX.value = withSpring(xForIndex(state.index, tabW, 0), SPRING);
181
- }, [pillX, state.index, tabW, tabWSV]);
182
-
183
- const selectIndex = useCallback(
184
- (index: number) => {
185
- const route = routesRef.current[index];
186
- if (!route) return;
187
- const width = tabWSV.value;
188
- if (width > 0) {
189
- pillX.value = withSpring(xForIndex(index, width, 0), SPRING);
190
- }
191
- const event = navigation.emit({
192
- type: "tabPress",
193
- target: route.key,
194
- canPreventDefault: true,
195
- });
196
- if (index === indexRef.current || event.defaultPrevented) return;
197
- void hapticSelection();
198
- navigation.navigate(route.name);
199
- },
200
- [navigation, pillX, tabWSV],
201
- );
202
-
203
- const setDragging = useCallback((value: boolean) => {
204
- dragging.current = value;
205
- }, []);
206
-
207
- const pan = Gesture.Pan()
208
- .enabled(count > 1 && tabW > 0)
209
- .activeOffsetX([-12, 12])
210
- .failOffsetY([-18, 18])
211
- .onStart(() => {
212
- cancelAnimation(pillX);
213
- dragStartX.value = pillX.value;
214
- dragStartIndex.value = nearestIndex(
215
- pillX.value,
216
- tabWSV.value,
217
- 0,
218
- countSV.value,
219
- );
220
- pressed.value = withSpring(1, SPRING);
221
- lastTick.value = dragStartIndex.value;
222
- runOnJS(setDragging)(true);
223
- })
224
- .onUpdate((e) => {
225
- const width = tabWSV.value;
226
- const n = countSV.value;
227
- const min = xForIndex(0, width, 0);
228
- const max = xForIndex(n - 1, width, 0);
229
- let next = dragStartX.value + e.translationX;
230
- if (next < min) next = min - rubberband(min - next, PILL_W);
231
- else if (next > max) next = max + rubberband(next - max, PILL_W);
232
- pillX.value = next;
233
- const idx = nearestIndex(next, width, 0, n);
234
- if (idx !== lastTick.value) {
235
- lastTick.value = idx;
236
- runOnJS(hapticSelection)();
237
- }
238
- })
239
- .onEnd((e) => {
240
- const width = tabWSV.value;
241
- const n = countSV.value;
242
- const from = dragStartIndex.value;
243
- const nearest = nearestIndex(pillX.value, width, 0, n);
244
- // Flick rapide : ±1 tab depuis le départ (pas de projection libre).
245
- // Relâchement lent : snap sur la tab sous le doigt (drag multi-tabs OK).
246
- let idx =
247
- Math.abs(e.velocityX) > FLING_VX
248
- ? from + (e.velocityX > 0 ? 1 : -1)
249
- : nearest;
250
- idx = Math.max(0, Math.min(n - 1, idx));
251
- pillX.value = withSpring(xForIndex(idx, width, 0), SPRING);
252
- pressed.value = withSpring(0, SPRING);
253
- runOnJS(selectIndex)(idx);
254
- })
255
- .onFinalize(() => {
256
- pressed.value = withSpring(0, SPRING);
257
- runOnJS(setDragging)(false);
258
- });
259
-
260
- const pillStyle = useAnimatedStyle(() => ({
261
- left: pillX.value,
262
- transform: [{ scale: interpolate(pressed.value, [0, 1], [1, 0.96]) }],
263
- }), []);
264
-
265
- return (
266
- <GestureHandlerRootView style={styles.gestureRoot}>
267
- <View
268
- style={[
269
- styles.bottomTab,
270
- themedStyles.bottomTab,
271
- { paddingBottom: Math.max(insets.bottom, 12) },
272
- ]}
273
- >
274
- <GestureDetector gesture={pan}>
275
- <View
276
- collapsable={false}
277
- style={styles.row}
278
- onLayout={(e) => setRowWidth(e.nativeEvent.layout.width)}
279
- >
280
- <Animated.View
281
- pointerEvents="none"
282
- style={[
283
- styles.pill,
284
- {
285
- backgroundColor: theme.colors.primary,
286
- borderRadius: t.radii.md,
287
- },
288
- pillStyle,
289
- ]}
290
- />
291
- {state.routes.map((route, index) => {
292
- const { options } = descriptors[route.key];
293
- const label =
294
- typeof options.title === "string"
295
- ? options.title
296
- : route.name;
297
-
298
- return (
299
- <TabItem
300
- key={route.key}
301
- index={index}
302
- label={label}
303
- selected={state.index === index}
304
- pillX={pillX}
305
- tabW={tabW}
306
- primary={theme.colors.primary}
307
- muted={muted}
308
- onPrimary={theme.colors.onPrimary}
309
- dragging={dragging}
310
- onPress={() => selectIndex(index)}
311
- icon={(color) =>
312
- options.tabBarIcon?.({
313
- focused: index === state.index,
314
- color,
315
- size: ICON_SIZE,
316
- })
317
- }
318
- />
319
- );
320
- })}
321
- </View>
322
- </GestureDetector>
323
- </View>
324
- </GestureHandlerRootView>
325
- );
326
- }
327
-
328
- const createThemedStyles = (theme: Theme) =>
329
- StyleSheet.create({
330
- bottomTab: {
331
- backgroundColor: theme.colors.surface,
332
- },
333
- });
334
-
335
- const styles = StyleSheet.create({
336
- gestureRoot: {
337
- width: "100%",
338
- },
339
- bottomTab: {
340
- width: "100%",
341
- paddingHorizontal: BAR_PAD_X,
342
- paddingTop: PILL_TOP,
343
- },
344
- row: {
345
- position: "relative",
346
- flexDirection: "row",
347
- alignItems: "flex-start",
348
- width: "100%",
349
- overflow: "visible",
350
- },
351
- pill: {
352
- position: "absolute",
353
- top: 0,
354
- width: PILL_W,
355
- height: PILL_H,
356
- zIndex: 0,
357
- },
358
- tabItem: {
359
- flex: 1,
360
- alignItems: "center",
361
- zIndex: 1,
362
- gap: 4,
363
- },
364
- iconSlot: {
365
- width: PILL_W,
366
- height: PILL_H,
367
- alignItems: "center",
368
- justifyContent: "center",
369
- },
370
- iconLayer: {
371
- ...StyleSheet.absoluteFillObject,
372
- alignItems: "center",
373
- justifyContent: "center",
374
- },
375
- labelSlot: {
376
- height: 16,
377
- alignItems: "center",
378
- justifyContent: "center",
379
- alignSelf: "stretch",
380
- },
381
- label: {
382
- fontSize: 13,
383
- textAlign: "center",
384
- },
385
- labelIdle: {
386
- fontWeight: "500",
387
- },
388
- labelActive: {
389
- position: "absolute",
390
- fontWeight: "700",
391
- },
392
- });
1
+ import {
2
+ useCallback,
3
+ useLayoutEffect,
4
+ useRef,
5
+ useState,
6
+ type MutableRefObject,
7
+ type ReactNode,
8
+ } from "react";
9
+ import type { BottomTabBarProps } from "@react-navigation/bottom-tabs";
10
+ import { Pressable, StyleSheet, View } from "react-native";
11
+ import { Gesture, GestureDetector, GestureHandlerRootView } from "react-native-gesture-handler";
12
+ import Animated, {
13
+ cancelAnimation,
14
+ Extrapolation,
15
+ interpolate,
16
+ runOnJS,
17
+ type SharedValue,
18
+ useAnimatedStyle,
19
+ useSharedValue,
20
+ withSpring,
21
+ } from "react-native-reanimated";
22
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
23
+ import { useTheme } from "../../contexts/ThemeContext";
24
+ import { Theme } from "../../types/Theme";
25
+ import { resolveTheme } from "../../helpers/themeStyles";
26
+ import { hapticSelection } from "../../helpers/haptics";
27
+
28
+ export type BottomTabProps = BottomTabBarProps;
29
+
30
+ /** Maquette Frame 25: 64×44 squircle behind the active icon. */
31
+ const PILL_W = 64;
32
+ const PILL_H = 44;
33
+ const ICON_SIZE = 24;
34
+ const BAR_PAD_X = 24;
35
+ const PILL_TOP = 12;
36
+ const SPRING = { damping: 18, stiffness: 220, mass: 0.85 };
37
+ /** Au-delà, un flick ne change qu’une tab (évite de sauter à la dernière). */
38
+ const FLING_VX = 650;
39
+
40
+ function xForIndex(index: number, tabW: number, padX: number) {
41
+ "worklet";
42
+ return padX + index * tabW + (tabW - PILL_W) / 2;
43
+ }
44
+
45
+ function nearestIndex(x: number, tabW: number, padX: number, count: number) {
46
+ "worklet";
47
+ if (tabW <= 0 || count <= 0) return 0;
48
+ const i = Math.round((x - padX - (tabW - PILL_W) / 2) / tabW);
49
+ return Math.max(0, Math.min(count - 1, i));
50
+ }
51
+
52
+ function tabProgress(pillX: number, index: number, tabW: number) {
53
+ "worklet";
54
+ if (tabW <= 0) return 0;
55
+ const tabCenter = index * tabW + tabW / 2;
56
+ const pillCenter = pillX + PILL_W / 2;
57
+ return interpolate(
58
+ Math.abs(pillCenter - tabCenter),
59
+ [0, tabW * 0.52],
60
+ [1, 0],
61
+ Extrapolation.CLAMP,
62
+ );
63
+ }
64
+
65
+ function rubberband(overshoot: number, dim: number) {
66
+ "worklet";
67
+ const c = 0.55;
68
+ return (1 - 1 / (overshoot * c / Math.max(dim, 1) + 1)) * dim;
69
+ }
70
+
71
+ function TabItem({
72
+ index,
73
+ label,
74
+ icon,
75
+ onPress,
76
+ selected,
77
+ pillX,
78
+ tabW,
79
+ primary,
80
+ muted,
81
+ onPrimary,
82
+ dragging,
83
+ }: {
84
+ index: number;
85
+ label: string;
86
+ icon: (color: string) => ReactNode;
87
+ onPress: () => void;
88
+ selected: boolean;
89
+ pillX: SharedValue<number>;
90
+ tabW: number;
91
+ primary: string;
92
+ muted: string;
93
+ onPrimary: string;
94
+ dragging: MutableRefObject<boolean>;
95
+ }) {
96
+ const idleIconStyle = useAnimatedStyle(() => ({
97
+ opacity: 1 - tabProgress(pillX.value, index, tabW),
98
+ }), [index, tabW]);
99
+
100
+ const activeIconStyle = useAnimatedStyle(() => ({
101
+ opacity: tabProgress(pillX.value, index, tabW),
102
+ }), [index, tabW]);
103
+
104
+ const idleLabelStyle = useAnimatedStyle(() => ({
105
+ opacity: 1 - tabProgress(pillX.value, index, tabW),
106
+ }), [index, tabW]);
107
+
108
+ const activeLabelStyle = useAnimatedStyle(() => ({
109
+ opacity: tabProgress(pillX.value, index, tabW),
110
+ }), [index, tabW]);
111
+
112
+ return (
113
+ <Pressable
114
+ onPress={() => {
115
+ if (dragging.current) return;
116
+ onPress();
117
+ }}
118
+ style={styles.tabItem}
119
+ accessibilityRole="tab"
120
+ accessibilityState={{ selected }}
121
+ accessibilityLabel={label}
122
+ >
123
+ <View style={styles.iconSlot}>
124
+ <Animated.View style={[styles.iconLayer, idleIconStyle]}>
125
+ {icon(muted)}
126
+ </Animated.View>
127
+ <Animated.View style={[styles.iconLayer, activeIconStyle]}>
128
+ {icon(onPrimary)}
129
+ </Animated.View>
130
+ </View>
131
+ <View style={styles.labelSlot}>
132
+ <Animated.Text
133
+ style={[styles.label, styles.labelIdle, { color: muted }, idleLabelStyle]}
134
+ numberOfLines={1}
135
+ >
136
+ {label}
137
+ </Animated.Text>
138
+ <Animated.Text
139
+ style={[styles.label, styles.labelActive, { color: primary }, activeLabelStyle]}
140
+ numberOfLines={1}
141
+ >
142
+ {label}
143
+ </Animated.Text>
144
+ </View>
145
+ </Pressable>
146
+ );
147
+ }
148
+
149
+ export function BottomTab({
150
+ state,
151
+ descriptors,
152
+ navigation,
153
+ }: BottomTabProps): ReactNode {
154
+ const { theme } = useTheme();
155
+ const t = resolveTheme(theme);
156
+ const insets = useSafeAreaInsets();
157
+ const themedStyles = createThemedStyles(theme);
158
+ const muted = t.colors.muted ?? theme.colors.onSurface;
159
+ const count = state.routes.length;
160
+
161
+ const [rowWidth, setRowWidth] = useState(0);
162
+ const tabW = count > 0 && rowWidth > 0 ? rowWidth / count : 0;
163
+ const pillX = useSharedValue(0);
164
+ const tabWSV = useSharedValue(0);
165
+ const countSV = useSharedValue(count);
166
+ const dragStartX = useSharedValue(0);
167
+ const dragStartIndex = useSharedValue(state.index);
168
+ const pressed = useSharedValue(0);
169
+ const lastTick = useSharedValue(state.index);
170
+ const dragging = useRef(false);
171
+ const routesRef = useRef(state.routes);
172
+ const indexRef = useRef(state.index);
173
+ routesRef.current = state.routes;
174
+ indexRef.current = state.index;
175
+ countSV.value = count;
176
+
177
+ useLayoutEffect(() => {
178
+ tabWSV.value = tabW;
179
+ if (tabW <= 0) return;
180
+ pillX.value = withSpring(xForIndex(state.index, tabW, 0), SPRING);
181
+ }, [pillX, state.index, tabW, tabWSV]);
182
+
183
+ const selectIndex = useCallback(
184
+ (index: number) => {
185
+ const route = routesRef.current[index];
186
+ if (!route) return;
187
+ const width = tabWSV.value;
188
+ if (width > 0) {
189
+ pillX.value = withSpring(xForIndex(index, width, 0), SPRING);
190
+ }
191
+ const event = navigation.emit({
192
+ type: "tabPress",
193
+ target: route.key,
194
+ canPreventDefault: true,
195
+ });
196
+ if (index === indexRef.current || event.defaultPrevented) return;
197
+ void hapticSelection();
198
+ navigation.navigate(route.name);
199
+ },
200
+ [navigation, pillX, tabWSV],
201
+ );
202
+
203
+ const setDragging = useCallback((value: boolean) => {
204
+ dragging.current = value;
205
+ }, []);
206
+
207
+ const pan = Gesture.Pan()
208
+ .enabled(count > 1 && tabW > 0)
209
+ .activeOffsetX([-12, 12])
210
+ .failOffsetY([-18, 18])
211
+ .onStart(() => {
212
+ cancelAnimation(pillX);
213
+ dragStartX.value = pillX.value;
214
+ dragStartIndex.value = nearestIndex(
215
+ pillX.value,
216
+ tabWSV.value,
217
+ 0,
218
+ countSV.value,
219
+ );
220
+ pressed.value = withSpring(1, SPRING);
221
+ lastTick.value = dragStartIndex.value;
222
+ runOnJS(setDragging)(true);
223
+ })
224
+ .onUpdate((e) => {
225
+ const width = tabWSV.value;
226
+ const n = countSV.value;
227
+ const min = xForIndex(0, width, 0);
228
+ const max = xForIndex(n - 1, width, 0);
229
+ let next = dragStartX.value + e.translationX;
230
+ if (next < min) next = min - rubberband(min - next, PILL_W);
231
+ else if (next > max) next = max + rubberband(next - max, PILL_W);
232
+ pillX.value = next;
233
+ const idx = nearestIndex(next, width, 0, n);
234
+ if (idx !== lastTick.value) {
235
+ lastTick.value = idx;
236
+ runOnJS(hapticSelection)();
237
+ }
238
+ })
239
+ .onEnd((e) => {
240
+ const width = tabWSV.value;
241
+ const n = countSV.value;
242
+ const from = dragStartIndex.value;
243
+ const nearest = nearestIndex(pillX.value, width, 0, n);
244
+ // Flick rapide : ±1 tab depuis le départ (pas de projection libre).
245
+ // Relâchement lent : snap sur la tab sous le doigt (drag multi-tabs OK).
246
+ let idx =
247
+ Math.abs(e.velocityX) > FLING_VX
248
+ ? from + (e.velocityX > 0 ? 1 : -1)
249
+ : nearest;
250
+ idx = Math.max(0, Math.min(n - 1, idx));
251
+ pillX.value = withSpring(xForIndex(idx, width, 0), SPRING);
252
+ pressed.value = withSpring(0, SPRING);
253
+ runOnJS(selectIndex)(idx);
254
+ })
255
+ .onFinalize(() => {
256
+ pressed.value = withSpring(0, SPRING);
257
+ runOnJS(setDragging)(false);
258
+ });
259
+
260
+ const pillStyle = useAnimatedStyle(() => ({
261
+ left: pillX.value,
262
+ transform: [{ scale: interpolate(pressed.value, [0, 1], [1, 0.96]) }],
263
+ }), []);
264
+
265
+ return (
266
+ <GestureHandlerRootView style={styles.gestureRoot}>
267
+ <View
268
+ style={[
269
+ styles.bottomTab,
270
+ themedStyles.bottomTab,
271
+ { paddingBottom: Math.max(insets.bottom, 12) },
272
+ ]}
273
+ >
274
+ <GestureDetector gesture={pan}>
275
+ <View
276
+ collapsable={false}
277
+ style={styles.row}
278
+ onLayout={(e) => setRowWidth(e.nativeEvent.layout.width)}
279
+ >
280
+ <Animated.View
281
+ pointerEvents="none"
282
+ style={[
283
+ styles.pill,
284
+ {
285
+ backgroundColor: theme.colors.primary,
286
+ borderRadius: t.radii.md,
287
+ },
288
+ pillStyle,
289
+ ]}
290
+ />
291
+ {state.routes.map((route, index) => {
292
+ const { options } = descriptors[route.key];
293
+ const label =
294
+ typeof options.title === "string"
295
+ ? options.title
296
+ : route.name;
297
+
298
+ return (
299
+ <TabItem
300
+ key={route.key}
301
+ index={index}
302
+ label={label}
303
+ selected={state.index === index}
304
+ pillX={pillX}
305
+ tabW={tabW}
306
+ primary={theme.colors.primary}
307
+ muted={muted}
308
+ onPrimary={theme.colors.onPrimary}
309
+ dragging={dragging}
310
+ onPress={() => selectIndex(index)}
311
+ icon={(color) =>
312
+ options.tabBarIcon?.({
313
+ focused: index === state.index,
314
+ color,
315
+ size: ICON_SIZE,
316
+ })
317
+ }
318
+ />
319
+ );
320
+ })}
321
+ </View>
322
+ </GestureDetector>
323
+ </View>
324
+ </GestureHandlerRootView>
325
+ );
326
+ }
327
+
328
+ const createThemedStyles = (theme: Theme) =>
329
+ StyleSheet.create({
330
+ bottomTab: {
331
+ backgroundColor: theme.colors.surface,
332
+ },
333
+ });
334
+
335
+ const styles = StyleSheet.create({
336
+ gestureRoot: {
337
+ width: "100%",
338
+ },
339
+ bottomTab: {
340
+ width: "100%",
341
+ paddingHorizontal: BAR_PAD_X,
342
+ paddingTop: PILL_TOP,
343
+ },
344
+ row: {
345
+ position: "relative",
346
+ flexDirection: "row",
347
+ alignItems: "flex-start",
348
+ width: "100%",
349
+ overflow: "visible",
350
+ },
351
+ pill: {
352
+ position: "absolute",
353
+ top: 0,
354
+ width: PILL_W,
355
+ height: PILL_H,
356
+ zIndex: 0,
357
+ },
358
+ tabItem: {
359
+ flex: 1,
360
+ alignItems: "center",
361
+ zIndex: 1,
362
+ gap: 4,
363
+ },
364
+ iconSlot: {
365
+ width: PILL_W,
366
+ height: PILL_H,
367
+ alignItems: "center",
368
+ justifyContent: "center",
369
+ },
370
+ iconLayer: {
371
+ ...StyleSheet.absoluteFillObject,
372
+ alignItems: "center",
373
+ justifyContent: "center",
374
+ },
375
+ labelSlot: {
376
+ height: 16,
377
+ alignItems: "center",
378
+ justifyContent: "center",
379
+ alignSelf: "stretch",
380
+ },
381
+ label: {
382
+ fontSize: 13,
383
+ textAlign: "center",
384
+ },
385
+ labelIdle: {
386
+ fontWeight: "500",
387
+ },
388
+ labelActive: {
389
+ position: "absolute",
390
+ fontWeight: "700",
391
+ },
392
+ });