@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,391 +1,415 @@
1
- import { Bell, ChevronLeftIcon, User } from "lucide-react-native";
2
- import {
3
- Image,
4
- Pressable,
5
- StyleSheet,
6
- View,
7
- type ImageStyle,
8
- } from "react-native";
9
- import { useTheme } from "../../contexts/ThemeContext";
10
- import { useWasto } from "../../contexts/WastoContext";
11
- import { useSafeAreaPadding } from "../../helpers/useSafeAreaPadding";
12
- import { Title } from "../title/Title";
13
- import { Theme } from "../../types/Theme";
14
- import { useMemo, type ReactNode } from "react";
15
- import { resolveTheme } from "../../helpers/themeStyles";
16
- import { useAnnouncements } from "../../contexts/AnnouncementsContext";
17
- import { hapticSelection } from "../../helpers/haptics";
18
- import { SPACE } from "../../helpers/layout";
19
- import { SYSTEM_ROUTES } from "../../helpers/systemRoutes";
20
- import { useAppNavigation } from "../../navigation/NavigationContext";
21
- import { publicMediaUrl } from "../../helpers/publicMediaUrl";
22
-
23
- export type AppHeaderSlot = "left" | "center" | "right";
24
-
25
- export type AppHeaderLogoElement = {
26
- id: string;
27
- type: "logo";
28
- slot: AppHeaderSlot;
29
- sourceType: "url" | "media";
30
- url?: string;
31
- mediaId?: string;
32
- };
33
-
34
- export type AppHeaderTitleElement = {
35
- id: string;
36
- type: "title";
37
- slot: AppHeaderSlot;
38
- useScreenTitle?: boolean;
39
- text?: string;
40
- };
41
-
42
- export type AppHeaderActionElement = {
43
- id: string;
44
- type: "action";
45
- slot: AppHeaderSlot;
46
- icon: string;
47
- label?: string;
48
- action: "navigate" | "back";
49
- href?: string;
50
- };
51
-
52
- export type AppHeaderElement =
53
- | AppHeaderLogoElement
54
- | AppHeaderTitleElement
55
- | AppHeaderActionElement;
56
-
57
- export type AppHeaderConfig = {
58
- elements: AppHeaderElement[];
59
- };
60
-
61
- export type HeaderProps = {
62
- readonly options: { title?: string; headerBackVisible?: boolean };
63
- readonly route: { name: string };
64
- readonly navigation: {
65
- canGoBack: () => boolean;
66
- goBack: () => void;
67
- };
68
- /** Flotte au-dessus du contenu (ex. carte) : fond transparent. */
69
- readonly overlay?: boolean;
70
- /** Config layout (`header.elements`) — logo / titre / actions. */
71
- readonly headerConfig?: AppHeaderConfig | null;
72
- };
73
-
74
- function resolveLogoUri(
75
- apiUrl: string,
76
- el: AppHeaderLogoElement,
77
- ): string | null {
78
- if (el.sourceType === "media") {
79
- return publicMediaUrl(apiUrl, el.mediaId);
80
- }
81
- const url = (el.url || "").trim();
82
- return url || null;
83
- }
84
-
85
- function HeaderLogo({
86
- element,
87
- }: {
88
- readonly element: AppHeaderLogoElement;
89
- }): ReactNode {
90
- const { apiUrl } = useWasto();
91
- const uri = resolveLogoUri(apiUrl, element);
92
- if (!uri) return null;
93
- return (
94
- <Image
95
- source={{ uri }}
96
- style={styles.logo as ImageStyle}
97
- resizeMode="contain"
98
- accessibilityLabel="Logo"
99
- />
100
- );
101
- }
102
-
103
- function HeaderActionButton({
104
- onPress,
105
- accessibilityLabel,
106
- children,
107
- themedStyles,
108
- borderRadius,
109
- }: {
110
- readonly onPress: () => void;
111
- readonly accessibilityLabel: string;
112
- readonly children: ReactNode;
113
- readonly themedStyles: ReturnType<typeof createThemedStyles>;
114
- readonly borderRadius: number;
115
- }): ReactNode {
116
- return (
117
- <Pressable
118
- onPress={onPress}
119
- style={[styles.iconBtn, themedStyles.iconBtn, { borderRadius }]}
120
- accessibilityLabel={accessibilityLabel}
121
- >
122
- {children}
123
- </Pressable>
124
- );
125
- }
126
-
127
- export function Header({
128
- options,
129
- route,
130
- navigation,
131
- overlay = false,
132
- headerConfig,
133
- }: HeaderProps): ReactNode {
134
- const { theme } = useTheme();
135
- const t = resolveTheme(theme);
136
- const themedStyles = createThemedStyles(theme);
137
- const topInset = useSafeAreaPadding(["top"]);
138
- const { hasUnread } = useAnnouncements();
139
- const { push } = useAppNavigation();
140
-
141
- const screenTitle = useMemo(
142
- () => options.title ?? route.name,
143
- [options.title, route.name],
144
- );
145
-
146
- const elements = headerConfig?.elements ?? [];
147
- const hasCustom = elements.length > 0;
148
- const hasCustomActions = elements.some((el) => el.type === "action");
149
-
150
- const bySlot = useMemo(() => {
151
- const left: AppHeaderElement[] = [];
152
- const center: AppHeaderElement[] = [];
153
- const right: AppHeaderElement[] = [];
154
- for (const el of elements) {
155
- if (el.slot === "center") center.push(el);
156
- else if (el.slot === "right") right.push(el);
157
- else left.push(el);
158
- }
159
- return { left, center, right };
160
- }, [elements]);
161
-
162
- const onBell = async () => {
163
- await hapticSelection();
164
- push(SYSTEM_ROUTES.notifications);
165
- };
166
-
167
- const onProfile = async () => {
168
- await hapticSelection();
169
- push(SYSTEM_ROUTES.profile);
170
- };
171
-
172
- const renderElement = (el: AppHeaderElement): ReactNode => {
173
- if (el.type === "logo") {
174
- return <HeaderLogo key={el.id} element={el} />;
175
- }
176
- if (el.type === "title") {
177
- const text =
178
- el.useScreenTitle !== false
179
- ? screenTitle
180
- : (el.text || "").trim() || screenTitle;
181
- return <Title key={el.id} text={text} level="1" />;
182
- }
183
- // action
184
- const onPress = async () => {
185
- await hapticSelection();
186
- if (el.action === "back") {
187
- if (navigation.canGoBack()) navigation.goBack();
188
- return;
189
- }
190
- const href = (el.href || "").trim();
191
- if (href) push(href);
192
- };
193
- const label = el.label?.trim() || el.icon || "Action";
194
- // Icônes système connues (bell / person) — le reste tombe sur Bell.
195
- const Icon =
196
- el.icon === "person" || el.icon === "users"
197
- ? User
198
- : Bell;
199
- return (
200
- <HeaderActionButton
201
- key={el.id}
202
- onPress={onPress}
203
- accessibilityLabel={label}
204
- themedStyles={themedStyles}
205
- borderRadius={t.radii.pill}
206
- >
207
- <Icon size={SPACE.iconGlyph} color={theme.colors.primary} />
208
- {el.icon === "bell" && hasUnread ? (
209
- <View
210
- style={[
211
- styles.badge,
212
- { backgroundColor: theme.colors.error },
213
- ]}
214
- />
215
- ) : null}
216
- </HeaderActionButton>
217
- );
218
- };
219
-
220
- const showBack =
221
- navigation.canGoBack() && options.headerBackVisible !== false;
222
-
223
- const defaultActions = (
224
- <>
225
- <HeaderActionButton
226
- onPress={onBell}
227
- accessibilityLabel="Notifications"
228
- themedStyles={themedStyles}
229
- borderRadius={t.radii.pill}
230
- >
231
- <Bell size={SPACE.iconGlyph} color={theme.colors.primary} />
232
- {hasUnread ? (
233
- <View
234
- style={[
235
- styles.badge,
236
- { backgroundColor: theme.colors.error },
237
- ]}
238
- />
239
- ) : null}
240
- </HeaderActionButton>
241
- <HeaderActionButton
242
- onPress={onProfile}
243
- accessibilityLabel="Profil"
244
- themedStyles={themedStyles}
245
- borderRadius={t.radii.pill}
246
- >
247
- <User size={SPACE.iconGlyph} color={theme.colors.primary} />
248
- </HeaderActionButton>
249
- </>
250
- );
251
-
252
- return (
253
- <View
254
- style={[
255
- styles.headerWrap,
256
- overlay ? undefined : themedStyles.headerWrap,
257
- topInset,
258
- ]}
259
- pointerEvents="box-none"
260
- >
261
- <View style={styles.header} pointerEvents="box-none">
262
- {hasCustom ? (
263
- <>
264
- <View style={styles.slotLeft} pointerEvents="box-none">
265
- {showBack ? (
266
- <HeaderActionButton
267
- onPress={() => navigation.goBack()}
268
- accessibilityLabel="Retour"
269
- themedStyles={themedStyles}
270
- borderRadius={t.radii.pill}
271
- >
272
- <ChevronLeftIcon
273
- size={SPACE.iconGlyph}
274
- color={theme.colors.onSurface}
275
- />
276
- </HeaderActionButton>
277
- ) : null}
278
- {bySlot.left.map(renderElement)}
279
- </View>
280
- <View
281
- style={styles.slotCenter}
282
- pointerEvents="box-none"
283
- >
284
- {bySlot.center.map(renderElement)}
285
- </View>
286
- <View style={styles.slotRight} pointerEvents="box-none">
287
- {bySlot.right.map(renderElement)}
288
- {!hasCustomActions ? defaultActions : null}
289
- </View>
290
- </>
291
- ) : (
292
- <>
293
- <View style={styles.left} pointerEvents="box-none">
294
- {showBack ? (
295
- <HeaderActionButton
296
- onPress={() => navigation.goBack()}
297
- accessibilityLabel="Retour"
298
- themedStyles={themedStyles}
299
- borderRadius={t.radii.pill}
300
- >
301
- <ChevronLeftIcon
302
- size={SPACE.iconGlyph}
303
- color={theme.colors.onSurface}
304
- />
305
- </HeaderActionButton>
306
- ) : null}
307
- <Title text={screenTitle} level="1" />
308
- </View>
309
- <View style={styles.actions}>{defaultActions}</View>
310
- </>
311
- )}
312
- </View>
313
- </View>
314
- );
315
- }
316
-
317
- const createThemedStyles = (theme: Theme) =>
318
- StyleSheet.create({
319
- headerWrap: {
320
- backgroundColor: theme.colors.background,
321
- },
322
- iconBtn: {
323
- backgroundColor: theme.colors.surface,
324
- borderWidth: 1,
325
- borderColor: theme.colors.border,
326
- },
327
- });
328
-
329
- const styles = StyleSheet.create({
330
- headerWrap: {},
331
- header: {
332
- flexDirection: "row",
333
- alignItems: "center",
334
- justifyContent: "space-between",
335
- paddingHorizontal: SPACE.pageX,
336
- paddingVertical: 12,
337
- gap: 10,
338
- minHeight: 56,
339
- },
340
- left: {
341
- flexDirection: "row",
342
- alignItems: "center",
343
- gap: 10,
344
- flex: 1,
345
- },
346
- slotLeft: {
347
- flexDirection: "row",
348
- alignItems: "center",
349
- gap: 10,
350
- flexShrink: 1,
351
- minWidth: 0,
352
- },
353
- slotCenter: {
354
- flex: 1,
355
- flexDirection: "row",
356
- alignItems: "center",
357
- justifyContent: "center",
358
- gap: 8,
359
- minWidth: 0,
360
- },
361
- slotRight: {
362
- flexDirection: "row",
363
- alignItems: "center",
364
- gap: 8,
365
- flexShrink: 0,
366
- },
367
- actions: {
368
- flexDirection: "row",
369
- alignItems: "center",
370
- gap: 8,
371
- },
372
- iconBtn: {
373
- width: SPACE.iconHit,
374
- height: SPACE.iconHit,
375
- alignItems: "center",
376
- justifyContent: "center",
377
- },
378
- badge: {
379
- position: "absolute",
380
- top: 4,
381
- right: 4,
382
- width: 12,
383
- height: 12,
384
- borderRadius: 6,
385
- },
386
- logo: {
387
- height: 32,
388
- width: 120,
389
- maxWidth: 160,
390
- },
391
- });
1
+ import { Bell, ChevronLeftIcon, User } from "lucide-react-native";
2
+ import {
3
+ Image,
4
+ Pressable,
5
+ StyleSheet,
6
+ View,
7
+ type ImageStyle,
8
+ } from "react-native";
9
+ import { useTheme } from "../../contexts/ThemeContext";
10
+ import { useWasto } from "../../contexts/WastoContext";
11
+ import { useSafeAreaPadding } from "../../helpers/useSafeAreaPadding";
12
+ import { Title } from "../title/Title";
13
+ import { Theme } from "../../types/Theme";
14
+ import { useMemo, type ReactNode } from "react";
15
+ import { resolveTheme } from "../../helpers/themeStyles";
16
+ import { useAnnouncements } from "../../contexts/AnnouncementsContext";
17
+ import { hapticSelection } from "../../helpers/haptics";
18
+ import { SPACE } from "../../helpers/layout";
19
+ import { SYSTEM_ROUTES } from "../../helpers/systemRoutes";
20
+ import { useAppNavigation } from "../../navigation/NavigationContext";
21
+ import { publicMediaUrl } from "../../helpers/publicMediaUrl";
22
+
23
+ export type AppHeaderSlot = "left" | "center" | "right";
24
+
25
+ export type AppHeaderLogoElement = {
26
+ id: string;
27
+ type: "logo";
28
+ slot: AppHeaderSlot;
29
+ sourceType: "url" | "media";
30
+ url?: string;
31
+ mediaId?: string;
32
+ };
33
+
34
+ export type AppHeaderTitleElement = {
35
+ id: string;
36
+ type: "title";
37
+ slot: AppHeaderSlot;
38
+ useScreenTitle?: boolean;
39
+ text?: string;
40
+ };
41
+
42
+ export type AppHeaderActionElement = {
43
+ id: string;
44
+ type: "action";
45
+ slot: AppHeaderSlot;
46
+ icon: string;
47
+ label?: string;
48
+ action: "navigate" | "back";
49
+ href?: string;
50
+ };
51
+
52
+ export type AppHeaderElement =
53
+ | AppHeaderLogoElement
54
+ | AppHeaderTitleElement
55
+ | AppHeaderActionElement;
56
+
57
+ export type AppHeaderConfig = {
58
+ elements: AppHeaderElement[];
59
+ };
60
+
61
+ /** Actions standard (notifications + profil) pour navbar sans titre. */
62
+ export const DEFAULT_HEADER_ACTIONS: readonly AppHeaderActionElement[] = [
63
+ {
64
+ id: "notifications",
65
+ type: "action",
66
+ slot: "right",
67
+ icon: "bell",
68
+ action: "navigate",
69
+ href: SYSTEM_ROUTES.notifications,
70
+ },
71
+ {
72
+ id: "profile",
73
+ type: "action",
74
+ slot: "right",
75
+ icon: "person",
76
+ action: "navigate",
77
+ href: SYSTEM_ROUTES.profile,
78
+ },
79
+ ];
80
+
81
+ export type HeaderProps = {
82
+ readonly options: { title?: string; headerBackVisible?: boolean };
83
+ readonly route: { name: string };
84
+ readonly navigation: {
85
+ canGoBack: () => boolean;
86
+ goBack: () => void;
87
+ };
88
+ /** Flotte au-dessus du contenu (ex. carte) : fond transparent. */
89
+ readonly overlay?: boolean;
90
+ /**
91
+ * Config layout (`header.elements`) — logo / actions.
92
+ * Si fournie (même vide), le fallback titre d’écran ne s’applique pas.
93
+ */
94
+ readonly headerConfig?: AppHeaderConfig | null;
95
+ };
96
+
97
+ function resolveLogoUri(
98
+ apiUrl: string,
99
+ el: AppHeaderLogoElement,
100
+ ): string | null {
101
+ if (el.sourceType === "media") {
102
+ return publicMediaUrl(apiUrl, el.mediaId);
103
+ }
104
+ const url = (el.url || "").trim();
105
+ return url || null;
106
+ }
107
+
108
+ function HeaderLogo({
109
+ element,
110
+ }: {
111
+ readonly element: AppHeaderLogoElement;
112
+ }): ReactNode {
113
+ const { apiUrl } = useWasto();
114
+ const uri = resolveLogoUri(apiUrl, element);
115
+ if (!uri) return null;
116
+ return (
117
+ <Image
118
+ source={{ uri }}
119
+ style={styles.logo as ImageStyle}
120
+ resizeMode="contain"
121
+ accessibilityLabel="Logo"
122
+ />
123
+ );
124
+ }
125
+
126
+ function HeaderActionButton({
127
+ onPress,
128
+ accessibilityLabel,
129
+ children,
130
+ themedStyles,
131
+ borderRadius,
132
+ }: {
133
+ readonly onPress: () => void;
134
+ readonly accessibilityLabel: string;
135
+ readonly children: ReactNode;
136
+ readonly themedStyles: ReturnType<typeof createThemedStyles>;
137
+ readonly borderRadius: number;
138
+ }): ReactNode {
139
+ return (
140
+ <Pressable
141
+ onPress={onPress}
142
+ style={[styles.iconBtn, themedStyles.iconBtn, { borderRadius }]}
143
+ accessibilityLabel={accessibilityLabel}
144
+ >
145
+ {children}
146
+ </Pressable>
147
+ );
148
+ }
149
+
150
+ export function Header({
151
+ options,
152
+ route,
153
+ navigation,
154
+ overlay = false,
155
+ headerConfig,
156
+ }: HeaderProps): ReactNode {
157
+ const { theme } = useTheme();
158
+ const t = resolveTheme(theme);
159
+ const themedStyles = createThemedStyles(theme);
160
+ const topInset = useSafeAreaPadding(["top"]);
161
+ const { hasUnread } = useAnnouncements();
162
+ const { push } = useAppNavigation();
163
+
164
+ const screenTitle = useMemo(
165
+ () => options.title ?? route.name,
166
+ [options.title, route.name],
167
+ );
168
+
169
+ /** Config explicite → navbar (logo/actions), jamais le fallback titre d’écran. */
170
+ const hasExplicitConfig = headerConfig != null;
171
+ const elements = useMemo(() => {
172
+ const raw = headerConfig?.elements ?? [];
173
+ // `type: "title"` est déprécié (navbar uniquement).
174
+ return raw.filter((el) => el.type !== "title");
175
+ }, [headerConfig]);
176
+ const hasCustomActions = elements.some((el) => el.type === "action");
177
+
178
+ const bySlot = useMemo(() => {
179
+ const left: AppHeaderElement[] = [];
180
+ const center: AppHeaderElement[] = [];
181
+ const right: AppHeaderElement[] = [];
182
+ for (const el of elements) {
183
+ if (el.slot === "center") center.push(el);
184
+ else if (el.slot === "right") right.push(el);
185
+ else left.push(el);
186
+ }
187
+ return { left, center, right };
188
+ }, [elements]);
189
+
190
+ const onBell = async () => {
191
+ await hapticSelection();
192
+ push(SYSTEM_ROUTES.notifications);
193
+ };
194
+
195
+ const onProfile = async () => {
196
+ await hapticSelection();
197
+ push(SYSTEM_ROUTES.profile);
198
+ };
199
+
200
+ const renderElement = (el: AppHeaderElement): ReactNode => {
201
+ if (el.type === "logo") {
202
+ return <HeaderLogo key={el.id} element={el} />;
203
+ }
204
+ if (el.type === "title") {
205
+ return null;
206
+ }
207
+ // action
208
+ const onPress = async () => {
209
+ await hapticSelection();
210
+ if (el.action === "back") {
211
+ if (navigation.canGoBack()) navigation.goBack();
212
+ return;
213
+ }
214
+ const href = (el.href || "").trim();
215
+ if (href) push(href);
216
+ };
217
+ const label = el.label?.trim() || el.icon || "Action";
218
+ // Icônes système connues (bell / person) — le reste tombe sur Bell.
219
+ const Icon =
220
+ el.icon === "person" || el.icon === "users"
221
+ ? User
222
+ : Bell;
223
+ return (
224
+ <HeaderActionButton
225
+ key={el.id}
226
+ onPress={onPress}
227
+ accessibilityLabel={label}
228
+ themedStyles={themedStyles}
229
+ borderRadius={t.radii.pill}
230
+ >
231
+ <Icon size={SPACE.iconGlyph} color={theme.colors.primary} />
232
+ {el.icon === "bell" && hasUnread ? (
233
+ <View
234
+ style={[
235
+ styles.badge,
236
+ { backgroundColor: theme.colors.error },
237
+ ]}
238
+ />
239
+ ) : null}
240
+ </HeaderActionButton>
241
+ );
242
+ };
243
+
244
+ const showBack =
245
+ navigation.canGoBack() && options.headerBackVisible !== false;
246
+
247
+ const defaultActions = (
248
+ <>
249
+ <HeaderActionButton
250
+ onPress={onBell}
251
+ accessibilityLabel="Notifications"
252
+ themedStyles={themedStyles}
253
+ borderRadius={t.radii.pill}
254
+ >
255
+ <Bell size={SPACE.iconGlyph} color={theme.colors.primary} />
256
+ {hasUnread ? (
257
+ <View
258
+ style={[
259
+ styles.badge,
260
+ { backgroundColor: theme.colors.error },
261
+ ]}
262
+ />
263
+ ) : null}
264
+ </HeaderActionButton>
265
+ <HeaderActionButton
266
+ onPress={onProfile}
267
+ accessibilityLabel="Profil"
268
+ themedStyles={themedStyles}
269
+ borderRadius={t.radii.pill}
270
+ >
271
+ <User size={SPACE.iconGlyph} color={theme.colors.primary} />
272
+ </HeaderActionButton>
273
+ </>
274
+ );
275
+
276
+ return (
277
+ <View
278
+ style={[
279
+ styles.headerWrap,
280
+ overlay ? undefined : themedStyles.headerWrap,
281
+ topInset,
282
+ ]}
283
+ pointerEvents="box-none"
284
+ >
285
+ <View style={styles.header} pointerEvents="box-none">
286
+ {hasExplicitConfig ? (
287
+ <>
288
+ <View style={styles.slotLeft} pointerEvents="box-none">
289
+ {showBack ? (
290
+ <HeaderActionButton
291
+ onPress={() => navigation.goBack()}
292
+ accessibilityLabel="Retour"
293
+ themedStyles={themedStyles}
294
+ borderRadius={t.radii.pill}
295
+ >
296
+ <ChevronLeftIcon
297
+ size={SPACE.iconGlyph}
298
+ color={theme.colors.onSurface}
299
+ />
300
+ </HeaderActionButton>
301
+ ) : null}
302
+ {bySlot.left.map(renderElement)}
303
+ </View>
304
+ <View
305
+ style={styles.slotCenter}
306
+ pointerEvents="box-none"
307
+ >
308
+ {bySlot.center.map(renderElement)}
309
+ </View>
310
+ <View style={styles.slotRight} pointerEvents="box-none">
311
+ {bySlot.right.map(renderElement)}
312
+ {!hasCustomActions ? defaultActions : null}
313
+ </View>
314
+ </>
315
+ ) : (
316
+ <>
317
+ <View style={styles.left} pointerEvents="box-none">
318
+ {showBack ? (
319
+ <HeaderActionButton
320
+ onPress={() => navigation.goBack()}
321
+ accessibilityLabel="Retour"
322
+ themedStyles={themedStyles}
323
+ borderRadius={t.radii.pill}
324
+ >
325
+ <ChevronLeftIcon
326
+ size={SPACE.iconGlyph}
327
+ color={theme.colors.onSurface}
328
+ />
329
+ </HeaderActionButton>
330
+ ) : null}
331
+ <Title text={screenTitle} level="1" />
332
+ </View>
333
+ <View style={styles.actions}>{defaultActions}</View>
334
+ </>
335
+ )}
336
+ </View>
337
+ </View>
338
+ );
339
+ }
340
+
341
+ const createThemedStyles = (theme: Theme) =>
342
+ StyleSheet.create({
343
+ headerWrap: {
344
+ backgroundColor: theme.colors.background,
345
+ },
346
+ iconBtn: {
347
+ backgroundColor: theme.colors.surface,
348
+ borderWidth: 1,
349
+ borderColor: theme.colors.border,
350
+ },
351
+ });
352
+
353
+ const styles = StyleSheet.create({
354
+ headerWrap: {},
355
+ header: {
356
+ flexDirection: "row",
357
+ alignItems: "center",
358
+ justifyContent: "space-between",
359
+ paddingHorizontal: SPACE.pageX,
360
+ paddingVertical: 12,
361
+ gap: 10,
362
+ minHeight: 56,
363
+ },
364
+ left: {
365
+ flexDirection: "row",
366
+ alignItems: "center",
367
+ gap: 10,
368
+ flex: 1,
369
+ },
370
+ slotLeft: {
371
+ flexDirection: "row",
372
+ alignItems: "center",
373
+ gap: 10,
374
+ flexShrink: 1,
375
+ minWidth: 0,
376
+ },
377
+ slotCenter: {
378
+ flex: 1,
379
+ flexDirection: "row",
380
+ alignItems: "center",
381
+ justifyContent: "center",
382
+ gap: 8,
383
+ minWidth: 0,
384
+ },
385
+ slotRight: {
386
+ flexDirection: "row",
387
+ alignItems: "center",
388
+ gap: 8,
389
+ flexShrink: 0,
390
+ },
391
+ actions: {
392
+ flexDirection: "row",
393
+ alignItems: "center",
394
+ gap: 8,
395
+ },
396
+ iconBtn: {
397
+ width: SPACE.iconHit,
398
+ height: SPACE.iconHit,
399
+ alignItems: "center",
400
+ justifyContent: "center",
401
+ },
402
+ badge: {
403
+ position: "absolute",
404
+ top: 4,
405
+ right: 4,
406
+ width: 12,
407
+ height: 12,
408
+ borderRadius: 6,
409
+ },
410
+ logo: {
411
+ height: 32,
412
+ width: 120,
413
+ maxWidth: 160,
414
+ },
415
+ });