@wasto/cms-components 1.5.10 → 1.5.11

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 (98) hide show
  1. package/README.md +47 -47
  2. package/dist/index.d.mts +103 -2
  3. package/dist/index.d.ts +103 -2
  4. package/dist/index.js +2861 -2442
  5. package/dist/index.mjs +3651 -3227
  6. package/package.json +2 -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 +391 -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 +527 -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/recycling-info/RecyclingInfo.tsx +189 -189
  49. package/src/components/safe-area/OptionalSafeAreaProvider.tsx +17 -17
  50. package/src/components/search/Search.tsx +320 -320
  51. package/src/components/select-street-modal/SelectStreetModal.tsx +475 -475
  52. package/src/components/title/Title.tsx +100 -100
  53. package/src/components/vision/Vision.tsx +447 -447
  54. package/src/components/vision/VisionActionCard.tsx +117 -117
  55. package/src/components/vision/VisionCapture.tsx +30 -30
  56. package/src/components/vision/VisionTapOverlay.tsx +122 -122
  57. package/src/contexts/AnnouncementsContext.tsx +171 -171
  58. package/src/contexts/AppDataContext.tsx +458 -0
  59. package/src/contexts/ChallengesContext.tsx +182 -182
  60. package/src/contexts/LocalContext.tsx +227 -227
  61. package/src/contexts/ThemeContext.tsx +37 -37
  62. package/src/contexts/WastoContext.tsx +130 -127
  63. package/src/helpers/blogPost.ts +72 -72
  64. package/src/helpers/generateQuizQuestions.ts +247 -247
  65. package/src/helpers/getContrastColor.ts +18 -18
  66. package/src/helpers/haptics.ts +20 -20
  67. package/src/helpers/hoursSchedule.ts +230 -230
  68. package/src/helpers/htmlContentToMarkdown.ts +114 -114
  69. package/src/helpers/layout.ts +54 -54
  70. package/src/helpers/loadLinearGradient.ts +22 -22
  71. package/src/helpers/mapLocations.ts +170 -0
  72. package/src/helpers/maquetteTheme.ts +76 -76
  73. package/src/helpers/markdownUnderlinePlugin.ts +32 -32
  74. package/src/helpers/nextCollection.ts +122 -0
  75. package/src/helpers/normalizeWasteTypeRecyclingInfo.ts +80 -80
  76. package/src/helpers/publicMediaUrl.ts +8 -8
  77. package/src/helpers/resolveApiAssetUrl.ts +21 -21
  78. package/src/helpers/systemRoutes.ts +7 -7
  79. package/src/helpers/themeStyles.ts +114 -114
  80. package/src/helpers/ttlCache.ts +41 -0
  81. package/src/helpers/useSafeAreaPadding.ts +14 -14
  82. package/src/hooks/useBadges.ts +100 -100
  83. package/src/hooks/useBlogPosts.ts +109 -105
  84. package/src/hooks/useChallenges.ts +110 -110
  85. package/src/hooks/useCities.ts +56 -56
  86. package/src/hooks/useCityAnnouncements.ts +118 -118
  87. package/src/hooks/useCollectionCalendar.ts +421 -421
  88. package/src/hooks/useColumns.ts +19 -19
  89. package/src/hooks/useConsignes.ts +62 -62
  90. package/src/hooks/useLocations.ts +120 -248
  91. package/src/hooks/useNextCollection.ts +163 -238
  92. package/src/hooks/useRecyclingInfo.ts +90 -90
  93. package/src/hooks/useWastoClient.ts +16 -16
  94. package/src/index.ts +149 -142
  95. package/src/navigation/NavigationContext.tsx +56 -56
  96. package/src/sentry/initSentry.ts +120 -120
  97. package/src/types/Theme.ts +72 -72
  98. package/src/types/css-modules.d.ts +1 -1
@@ -1,247 +1,247 @@
1
- import { useCallback, type ReactNode } from "react";
2
- import {
3
- ActivityIndicator,
4
- FlatList,
5
- Pressable,
6
- StyleSheet,
7
- Text,
8
- View,
9
- } from "react-native";
10
- import { useTheme } from "../../contexts/ThemeContext";
11
- import { resolveTheme, cardStyle } from "../../helpers/themeStyles";
12
- import { SPACE } from "../../helpers/layout";
13
- import {
14
- useCityAnnouncements,
15
- type CityAnnouncementItem,
16
- } from "../../hooks/useCityAnnouncements";
17
- import { Button } from "../button/Button";
18
-
19
- function formatSentAt(value?: string | null) {
20
- if (!value) return null;
21
- const d = new Date(value);
22
- if (Number.isNaN(d.getTime())) return null;
23
- return d.toLocaleDateString("fr-FR", {
24
- day: "numeric",
25
- month: "short",
26
- year: "numeric",
27
- });
28
- }
29
-
30
- function excerpt(body: string, max = 120) {
31
- const t = body.trim().replace(/\s+/g, " ");
32
- if (t.length <= max) return t;
33
- return `${t.slice(0, max).trim()}…`;
34
- }
35
-
36
- /** Inbox list — detail uses the shared AnnouncementModal (WastoProvider). */
37
- export function NotificationsScreen(): ReactNode {
38
- const { theme } = useTheme();
39
- const t = resolveTheme(theme);
40
- const {
41
- items,
42
- loading,
43
- error,
44
- hasMore,
45
- loadMore,
46
- reload,
47
- openItem,
48
- hasPlaceSelected,
49
- totalCount,
50
- } = useCityAnnouncements();
51
-
52
- const renderItem = useCallback(
53
- ({ item }: { item: CityAnnouncementItem }) => {
54
- const dateLabel = formatSentAt(item.sentAt);
55
- return (
56
- <Pressable
57
- onPress={() => void openItem(item)}
58
- style={[
59
- styles.row,
60
- cardStyle(theme),
61
- { borderRadius: t.radii.md },
62
- ]}
63
- accessibilityRole="button"
64
- accessibilityLabel={item.title}
65
- >
66
- <View style={styles.rowHeader}>
67
- <Text
68
- style={[styles.rowTitle, { color: theme.colors.onSurface }]}
69
- numberOfLines={2}
70
- >
71
- {item.title}
72
- </Text>
73
- {item.unread ? (
74
- <View
75
- style={[
76
- styles.unreadDot,
77
- { backgroundColor: theme.colors.primary },
78
- ]}
79
- />
80
- ) : null}
81
- </View>
82
- {dateLabel ? (
83
- <Text style={[styles.rowMeta, { color: t.colors.muted }]}>
84
- {dateLabel}
85
- </Text>
86
- ) : null}
87
- <Text
88
- style={[styles.rowBody, { color: t.colors.muted }]}
89
- numberOfLines={3}
90
- >
91
- {excerpt(item.body)}
92
- </Text>
93
- </Pressable>
94
- );
95
- },
96
- [openItem, t.colors.muted, t.radii.md, theme],
97
- );
98
-
99
- if (!hasPlaceSelected) {
100
- return (
101
- <View style={styles.center}>
102
- <Text style={[styles.emptyTitle, { color: theme.colors.onSurface }]}>
103
- Aucun secteur sélectionné
104
- </Text>
105
- <Text style={[styles.emptyText, { color: t.colors.muted }]}>
106
- Choisissez votre rue pour voir les notifications de votre ville.
107
- </Text>
108
- </View>
109
- );
110
- }
111
-
112
- if (loading && items.length === 0) {
113
- return (
114
- <View style={styles.center}>
115
- <ActivityIndicator color={theme.colors.primary} />
116
- </View>
117
- );
118
- }
119
-
120
- if (error && items.length === 0) {
121
- return (
122
- <View style={styles.center}>
123
- <Text style={[styles.emptyTitle, { color: theme.colors.error }]}>
124
- {error}
125
- </Text>
126
- <Button variant="secondary" onPress={() => void reload()} style={styles.retry}>
127
- Réessayer
128
- </Button>
129
- </View>
130
- );
131
- }
132
-
133
- return (
134
- <View style={styles.screen}>
135
- <FlatList
136
- data={items}
137
- keyExtractor={(item) => item.id}
138
- renderItem={renderItem}
139
- contentContainerStyle={styles.list}
140
- onEndReached={() => {
141
- if (hasMore) loadMore();
142
- }}
143
- onEndReachedThreshold={0.4}
144
- ListEmptyComponent={
145
- <View style={styles.centerInline}>
146
- <Text style={[styles.emptyTitle, { color: theme.colors.onSurface }]}>
147
- Aucune notification
148
- </Text>
149
- <Text style={[styles.emptyText, { color: t.colors.muted }]}>
150
- Les annonces de votre ville apparaîtront ici.
151
- </Text>
152
- </View>
153
- }
154
- ListFooterComponent={
155
- hasMore ? (
156
- <Button
157
- variant="ghost"
158
- onPress={loadMore}
159
- style={styles.loadMore}
160
- >
161
- {`Voir plus (${items.length}/${totalCount})`}
162
- </Button>
163
- ) : items.length > 0 ? (
164
- <Text style={[styles.footerHint, { color: t.colors.muted }]}>
165
- {totalCount} notification{totalCount > 1 ? "s" : ""}
166
- </Text>
167
- ) : null
168
- }
169
- />
170
- </View>
171
- );
172
- }
173
-
174
- const styles = StyleSheet.create({
175
- screen: {
176
- flex: 1,
177
- },
178
- list: {
179
- paddingHorizontal: SPACE.pageX,
180
- paddingVertical: SPACE.sectionY,
181
- gap: SPACE.stack,
182
- flexGrow: 1,
183
- },
184
- row: {
185
- padding: SPACE.cardPad,
186
- gap: 6,
187
- },
188
- rowHeader: {
189
- flexDirection: "row",
190
- alignItems: "flex-start",
191
- gap: 8,
192
- },
193
- rowTitle: {
194
- flex: 1,
195
- fontSize: 16,
196
- fontWeight: "700",
197
- },
198
- unreadDot: {
199
- width: 10,
200
- height: 10,
201
- borderRadius: 5,
202
- marginTop: 5,
203
- },
204
- rowMeta: {
205
- fontSize: 12,
206
- fontWeight: "600",
207
- },
208
- rowBody: {
209
- fontSize: 14,
210
- lineHeight: 20,
211
- },
212
- center: {
213
- flex: 1,
214
- alignItems: "center",
215
- justifyContent: "center",
216
- padding: SPACE.pageX,
217
- gap: 8,
218
- },
219
- centerInline: {
220
- paddingVertical: 48,
221
- alignItems: "center",
222
- gap: 8,
223
- },
224
- emptyTitle: {
225
- fontSize: 17,
226
- fontWeight: "700",
227
- textAlign: "center",
228
- },
229
- emptyText: {
230
- fontSize: 14,
231
- textAlign: "center",
232
- lineHeight: 20,
233
- },
234
- retry: {
235
- marginTop: 12,
236
- alignSelf: "stretch",
237
- },
238
- loadMore: {
239
- marginTop: 8,
240
- },
241
- footerHint: {
242
- textAlign: "center",
243
- fontSize: 12,
244
- marginTop: 8,
245
- marginBottom: 16,
246
- },
247
- });
1
+ import { useCallback, type ReactNode } from "react";
2
+ import {
3
+ ActivityIndicator,
4
+ FlatList,
5
+ Pressable,
6
+ StyleSheet,
7
+ Text,
8
+ View,
9
+ } from "react-native";
10
+ import { useTheme } from "../../contexts/ThemeContext";
11
+ import { resolveTheme, cardStyle } from "../../helpers/themeStyles";
12
+ import { SPACE } from "../../helpers/layout";
13
+ import {
14
+ useCityAnnouncements,
15
+ type CityAnnouncementItem,
16
+ } from "../../hooks/useCityAnnouncements";
17
+ import { Button } from "../button/Button";
18
+
19
+ function formatSentAt(value?: string | null) {
20
+ if (!value) return null;
21
+ const d = new Date(value);
22
+ if (Number.isNaN(d.getTime())) return null;
23
+ return d.toLocaleDateString("fr-FR", {
24
+ day: "numeric",
25
+ month: "short",
26
+ year: "numeric",
27
+ });
28
+ }
29
+
30
+ function excerpt(body: string, max = 120) {
31
+ const t = body.trim().replace(/\s+/g, " ");
32
+ if (t.length <= max) return t;
33
+ return `${t.slice(0, max).trim()}…`;
34
+ }
35
+
36
+ /** Inbox list — detail uses the shared AnnouncementModal (WastoProvider). */
37
+ export function NotificationsScreen(): ReactNode {
38
+ const { theme } = useTheme();
39
+ const t = resolveTheme(theme);
40
+ const {
41
+ items,
42
+ loading,
43
+ error,
44
+ hasMore,
45
+ loadMore,
46
+ reload,
47
+ openItem,
48
+ hasPlaceSelected,
49
+ totalCount,
50
+ } = useCityAnnouncements();
51
+
52
+ const renderItem = useCallback(
53
+ ({ item }: { item: CityAnnouncementItem }) => {
54
+ const dateLabel = formatSentAt(item.sentAt);
55
+ return (
56
+ <Pressable
57
+ onPress={() => void openItem(item)}
58
+ style={[
59
+ styles.row,
60
+ cardStyle(theme),
61
+ { borderRadius: t.radii.md },
62
+ ]}
63
+ accessibilityRole="button"
64
+ accessibilityLabel={item.title}
65
+ >
66
+ <View style={styles.rowHeader}>
67
+ <Text
68
+ style={[styles.rowTitle, { color: theme.colors.onSurface }]}
69
+ numberOfLines={2}
70
+ >
71
+ {item.title}
72
+ </Text>
73
+ {item.unread ? (
74
+ <View
75
+ style={[
76
+ styles.unreadDot,
77
+ { backgroundColor: theme.colors.primary },
78
+ ]}
79
+ />
80
+ ) : null}
81
+ </View>
82
+ {dateLabel ? (
83
+ <Text style={[styles.rowMeta, { color: t.colors.muted }]}>
84
+ {dateLabel}
85
+ </Text>
86
+ ) : null}
87
+ <Text
88
+ style={[styles.rowBody, { color: t.colors.muted }]}
89
+ numberOfLines={3}
90
+ >
91
+ {excerpt(item.body)}
92
+ </Text>
93
+ </Pressable>
94
+ );
95
+ },
96
+ [openItem, t.colors.muted, t.radii.md, theme],
97
+ );
98
+
99
+ if (!hasPlaceSelected) {
100
+ return (
101
+ <View style={styles.center}>
102
+ <Text style={[styles.emptyTitle, { color: theme.colors.onSurface }]}>
103
+ Aucun secteur sélectionné
104
+ </Text>
105
+ <Text style={[styles.emptyText, { color: t.colors.muted }]}>
106
+ Choisissez votre rue pour voir les notifications de votre ville.
107
+ </Text>
108
+ </View>
109
+ );
110
+ }
111
+
112
+ if (loading && items.length === 0) {
113
+ return (
114
+ <View style={styles.center}>
115
+ <ActivityIndicator color={theme.colors.primary} />
116
+ </View>
117
+ );
118
+ }
119
+
120
+ if (error && items.length === 0) {
121
+ return (
122
+ <View style={styles.center}>
123
+ <Text style={[styles.emptyTitle, { color: theme.colors.error }]}>
124
+ {error}
125
+ </Text>
126
+ <Button variant="secondary" onPress={() => void reload()} style={styles.retry}>
127
+ Réessayer
128
+ </Button>
129
+ </View>
130
+ );
131
+ }
132
+
133
+ return (
134
+ <View style={styles.screen}>
135
+ <FlatList
136
+ data={items}
137
+ keyExtractor={(item) => item.id}
138
+ renderItem={renderItem}
139
+ contentContainerStyle={styles.list}
140
+ onEndReached={() => {
141
+ if (hasMore) loadMore();
142
+ }}
143
+ onEndReachedThreshold={0.4}
144
+ ListEmptyComponent={
145
+ <View style={styles.centerInline}>
146
+ <Text style={[styles.emptyTitle, { color: theme.colors.onSurface }]}>
147
+ Aucune notification
148
+ </Text>
149
+ <Text style={[styles.emptyText, { color: t.colors.muted }]}>
150
+ Les annonces de votre ville apparaîtront ici.
151
+ </Text>
152
+ </View>
153
+ }
154
+ ListFooterComponent={
155
+ hasMore ? (
156
+ <Button
157
+ variant="ghost"
158
+ onPress={loadMore}
159
+ style={styles.loadMore}
160
+ >
161
+ {`Voir plus (${items.length}/${totalCount})`}
162
+ </Button>
163
+ ) : items.length > 0 ? (
164
+ <Text style={[styles.footerHint, { color: t.colors.muted }]}>
165
+ {totalCount} notification{totalCount > 1 ? "s" : ""}
166
+ </Text>
167
+ ) : null
168
+ }
169
+ />
170
+ </View>
171
+ );
172
+ }
173
+
174
+ const styles = StyleSheet.create({
175
+ screen: {
176
+ flex: 1,
177
+ },
178
+ list: {
179
+ paddingHorizontal: SPACE.pageX,
180
+ paddingVertical: SPACE.sectionY,
181
+ gap: SPACE.stack,
182
+ flexGrow: 1,
183
+ },
184
+ row: {
185
+ padding: SPACE.cardPad,
186
+ gap: 6,
187
+ },
188
+ rowHeader: {
189
+ flexDirection: "row",
190
+ alignItems: "flex-start",
191
+ gap: 8,
192
+ },
193
+ rowTitle: {
194
+ flex: 1,
195
+ fontSize: 16,
196
+ fontWeight: "700",
197
+ },
198
+ unreadDot: {
199
+ width: 10,
200
+ height: 10,
201
+ borderRadius: 5,
202
+ marginTop: 5,
203
+ },
204
+ rowMeta: {
205
+ fontSize: 12,
206
+ fontWeight: "600",
207
+ },
208
+ rowBody: {
209
+ fontSize: 14,
210
+ lineHeight: 20,
211
+ },
212
+ center: {
213
+ flex: 1,
214
+ alignItems: "center",
215
+ justifyContent: "center",
216
+ padding: SPACE.pageX,
217
+ gap: 8,
218
+ },
219
+ centerInline: {
220
+ paddingVertical: 48,
221
+ alignItems: "center",
222
+ gap: 8,
223
+ },
224
+ emptyTitle: {
225
+ fontSize: 17,
226
+ fontWeight: "700",
227
+ textAlign: "center",
228
+ },
229
+ emptyText: {
230
+ fontSize: 14,
231
+ textAlign: "center",
232
+ lineHeight: 20,
233
+ },
234
+ retry: {
235
+ marginTop: 12,
236
+ alignSelf: "stretch",
237
+ },
238
+ loadMore: {
239
+ marginTop: 8,
240
+ },
241
+ footerHint: {
242
+ textAlign: "center",
243
+ fontSize: 12,
244
+ marginTop: 8,
245
+ marginBottom: 16,
246
+ },
247
+ });
@@ -1,64 +1,102 @@
1
- import { PropsWithChildren, type ReactNode } from "react";
2
- import { ScrollView, StyleSheet, View } from "react-native";
3
- import { useTheme } from "../../contexts/ThemeContext";
4
- import { useSafeAreaPadding } from "../../helpers/useSafeAreaPadding";
5
- import { SPACE } from "../../helpers/layout";
6
- import { Theme } from "../../types/Theme";
7
-
8
- export type PageProps = PropsWithChildren & {
9
- /** When false, content fills the screen without scrolling (e.g. fullScreen map). Default true. */
10
- scroll?: boolean;
11
- };
12
-
13
- /**
14
- * Page shell: top safe area + optional vertical scroll.
15
- * No global horizontal padding — each block uses ContentInset or is full-bleed
16
- * (map, calendar grid). Bottom inset is handled by BottomTab when using tabs.
17
- */
18
- export function Page({ children, scroll = true }: PageProps): ReactNode {
19
- const { theme } = useTheme();
20
- const themedStyles = createThemedStyles(theme);
21
- const topInset = useSafeAreaPadding(["top"]);
22
-
23
- return (
24
- <View style={[styles.root, themedStyles.root, topInset]}>
25
- {scroll ? (
26
- <ScrollView
27
- style={styles.scroll}
28
- contentContainerStyle={styles.scrollContent}
29
- keyboardShouldPersistTaps="handled"
30
- showsVerticalScrollIndicator={false}
31
- >
32
- {children}
33
- </ScrollView>
34
- ) : (
35
- <View style={styles.fill}>{children}</View>
36
- )}
37
- </View>
38
- );
39
- }
40
-
41
- const createThemedStyles = (theme: Theme) =>
42
- StyleSheet.create({
43
- root: {
44
- backgroundColor: theme.colors.background,
45
- },
46
- });
47
-
48
- const styles = StyleSheet.create({
49
- root: {
50
- flex: 1,
51
- },
52
- scroll: {
53
- flex: 1,
54
- },
55
- scrollContent: {
56
- flexGrow: 1,
57
- gap: SPACE.sectionY,
58
- paddingBottom: 28,
59
- },
60
- fill: {
61
- flex: 1,
62
- gap: SPACE.sectionY,
63
- },
64
- });
1
+ import { PropsWithChildren, useCallback, useState, type ReactNode } from "react";
2
+ import { RefreshControl, ScrollView, StyleSheet, View } from "react-native";
3
+ import { useTheme } from "../../contexts/ThemeContext";
4
+ import { useOptionalAppData } from "../../contexts/AppDataContext";
5
+ import { useSafeAreaPadding } from "../../helpers/useSafeAreaPadding";
6
+ import { SPACE } from "../../helpers/layout";
7
+ import { Theme } from "../../types/Theme";
8
+ import { resolveTheme } from "../../helpers/themeStyles";
9
+
10
+ export type PageProps = PropsWithChildren & {
11
+ /** When false, content fills the screen without scrolling (e.g. fullScreen map). Default true. */
12
+ scroll?: boolean;
13
+ /**
14
+ * Pull-to-refresh : force refresh du cache tri + carte (TTL 1 semaine).
15
+ * Default true when scrollable.
16
+ */
17
+ pullToRefresh?: boolean;
18
+ };
19
+
20
+ /**
21
+ * Page shell: top safe area + optional vertical scroll.
22
+ * No global horizontal padding — each block uses ContentInset or is full-bleed
23
+ * (map, calendar grid). Bottom inset is handled by BottomTab when using tabs.
24
+ */
25
+ export function Page({
26
+ children,
27
+ scroll = true,
28
+ pullToRefresh,
29
+ }: PageProps): ReactNode {
30
+ const { theme } = useTheme();
31
+ const t = resolveTheme(theme);
32
+ const themedStyles = createThemedStyles(theme);
33
+ const topInset = useSafeAreaPadding(["top"]);
34
+ const appData = useOptionalAppData();
35
+ const [refreshing, setRefreshing] = useState(false);
36
+
37
+ const enableRefresh = pullToRefresh ?? scroll;
38
+
39
+ const onRefresh = useCallback(async () => {
40
+ if (!appData) return;
41
+ setRefreshing(true);
42
+ try {
43
+ await appData.refreshCachedData();
44
+ } finally {
45
+ setRefreshing(false);
46
+ }
47
+ }, [appData]);
48
+
49
+ return (
50
+ <View style={[styles.root, themedStyles.root, topInset]}>
51
+ {scroll ? (
52
+ <ScrollView
53
+ style={styles.scroll}
54
+ contentContainerStyle={styles.scrollContent}
55
+ keyboardShouldPersistTaps="handled"
56
+ showsVerticalScrollIndicator={false}
57
+ refreshControl={
58
+ enableRefresh && appData ? (
59
+ <RefreshControl
60
+ refreshing={refreshing}
61
+ onRefresh={() => {
62
+ void onRefresh();
63
+ }}
64
+ tintColor={t.colors.primary}
65
+ colors={[t.colors.primary]}
66
+ />
67
+ ) : undefined
68
+ }
69
+ >
70
+ {children}
71
+ </ScrollView>
72
+ ) : (
73
+ <View style={styles.fill}>{children}</View>
74
+ )}
75
+ </View>
76
+ );
77
+ }
78
+
79
+ const createThemedStyles = (theme: Theme) =>
80
+ StyleSheet.create({
81
+ root: {
82
+ backgroundColor: theme.colors.background,
83
+ },
84
+ });
85
+
86
+ const styles = StyleSheet.create({
87
+ root: {
88
+ flex: 1,
89
+ },
90
+ scroll: {
91
+ flex: 1,
92
+ },
93
+ scrollContent: {
94
+ flexGrow: 1,
95
+ gap: SPACE.sectionY,
96
+ paddingBottom: 28,
97
+ },
98
+ fill: {
99
+ flex: 1,
100
+ gap: SPACE.sectionY,
101
+ },
102
+ });