@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.
- package/README.md +47 -47
- package/dist/index.d.mts +181 -51
- package/dist/index.d.ts +181 -51
- package/dist/index.js +3614 -3015
- package/dist/index.mjs +3021 -2418
- package/package.json +12 -2
- package/src/components/announcement-modal/AnnouncementModal.tsx +183 -183
- package/src/components/article/Article.tsx +21 -21
- package/src/components/article/ArticleCard.tsx +81 -81
- package/src/components/article/ArticleExcerpts.tsx +80 -80
- package/src/components/article/ArticleList.tsx +114 -114
- package/src/components/article/ArticleMarkdown.tsx +170 -170
- package/src/components/article/ArticleReaderModal.tsx +93 -93
- package/src/components/article/ArticleSingle.tsx +57 -57
- package/src/components/bottom-tab/BottomTab.tsx +392 -392
- package/src/components/button/Button.tsx +154 -154
- package/src/components/challenge/Badges.tsx +84 -84
- package/src/components/challenge/BadgesModal.tsx +166 -166
- package/src/components/challenge/Challenge.tsx +380 -380
- package/src/components/challenge/ChallengeModal.tsx +231 -231
- package/src/components/challenge/ChallengeVignette.tsx +249 -249
- package/src/components/challenge/ChallengesModal.tsx +243 -243
- package/src/components/challenge/QuizModal.tsx +381 -381
- package/src/components/challenge/ResultModal.tsx +144 -144
- package/src/components/chat/Chat.tsx +928 -928
- package/src/components/collection-calendar/CollectionCalendar.tsx +274 -274
- package/src/components/columns/Columns.tsx +33 -33
- package/src/components/consignes-modal/ConsignesModal.tsx +267 -267
- package/src/components/content-inset/ContentInset.tsx +33 -33
- package/src/components/header/Header.tsx +415 -391
- package/src/components/image/Image.tsx +15 -15
- package/src/components/image/ImageFrame.tsx +102 -102
- package/src/components/image/ImageMedia.tsx +31 -31
- package/src/components/image/ImageUrl.tsx +30 -30
- package/src/components/locations-map/LocationSheet.tsx +417 -417
- package/src/components/locations-map/LocationsMap.native.tsx +260 -260
- package/src/components/locations-map/LocationsMap.tsx +13 -13
- package/src/components/locations-map/LocationsMap.web.tsx +10 -10
- package/src/components/locations-map/LocationsMapShell.tsx +546 -527
- package/src/components/locations-map/LocationsMapView.tsx +108 -108
- package/src/components/locations-map/LocationsMapView.web.tsx +331 -331
- package/src/components/nav-button/NavButton.tsx +59 -59
- package/src/components/next-collection/NextCollection.tsx +636 -621
- package/src/components/notifications/NotificationsScreen.tsx +247 -247
- package/src/components/page/Page.tsx +102 -64
- package/src/components/parapraph/Paragraph.tsx +67 -67
- package/src/components/profile/ProfileScreen.tsx +236 -236
- package/src/components/push/PushTokenRegistrar.tsx +47 -0
- package/src/components/recycling-info/RecyclingInfo.tsx +189 -189
- package/src/components/safe-area/OptionalSafeAreaProvider.tsx +17 -17
- package/src/components/search/Search.tsx +320 -320
- package/src/components/select-street-modal/SelectStreetModal.tsx +475 -475
- package/src/components/title/Title.tsx +100 -100
- package/src/components/vision/Vision.tsx +447 -447
- package/src/components/vision/VisionActionCard.tsx +117 -117
- package/src/components/vision/VisionCapture.tsx +30 -30
- package/src/components/vision/VisionTapOverlay.tsx +122 -122
- package/src/contexts/AnnouncementsContext.tsx +171 -171
- package/src/contexts/AppDataContext.tsx +458 -0
- package/src/contexts/ChallengesContext.tsx +182 -182
- package/src/contexts/HeaderConfigContext.tsx +29 -0
- package/src/contexts/LocalContext.tsx +227 -227
- package/src/contexts/ThemeContext.tsx +37 -37
- package/src/contexts/WastoContext.tsx +132 -127
- package/src/helpers/blogPost.ts +72 -72
- package/src/helpers/generateQuizQuestions.ts +247 -247
- package/src/helpers/getContrastColor.ts +18 -18
- package/src/helpers/haptics.ts +20 -20
- package/src/helpers/hoursSchedule.ts +230 -230
- package/src/helpers/htmlContentToMarkdown.ts +114 -114
- package/src/helpers/layout.ts +54 -54
- package/src/helpers/loadLinearGradient.ts +22 -22
- package/src/helpers/mapLocations.ts +170 -0
- package/src/helpers/maquetteTheme.ts +76 -76
- package/src/helpers/markdownUnderlinePlugin.ts +32 -32
- package/src/helpers/nextCollection.ts +122 -0
- package/src/helpers/normalizeWasteTypeRecyclingInfo.ts +80 -80
- package/src/helpers/publicMediaUrl.ts +8 -8
- package/src/helpers/resolveApiAssetUrl.ts +21 -21
- package/src/helpers/systemRoutes.ts +7 -7
- package/src/helpers/themeStyles.ts +114 -114
- package/src/helpers/ttlCache.ts +41 -0
- package/src/helpers/useSafeAreaPadding.ts +14 -14
- package/src/hooks/useBadges.ts +100 -100
- package/src/hooks/useBlogPosts.ts +109 -105
- package/src/hooks/useChallenges.ts +110 -110
- package/src/hooks/useCities.ts +56 -56
- package/src/hooks/useCityAnnouncements.ts +118 -118
- package/src/hooks/useCollectionCalendar.ts +421 -421
- package/src/hooks/useColumns.ts +19 -19
- package/src/hooks/useConsignes.ts +62 -62
- package/src/hooks/useLocations.ts +120 -248
- package/src/hooks/useNextCollection.ts +163 -238
- package/src/hooks/useRecyclingInfo.ts +90 -90
- package/src/hooks/useWastoClient.ts +16 -16
- package/src/index.ts +161 -142
- package/src/navigation/NavigationContext.tsx +56 -56
- package/src/push/registerExpoPushToken.ts +133 -0
- package/src/sentry/initSentry.ts +120 -120
- package/src/types/Theme.ts +72 -72
- package/src/types/css-modules.d.ts +1 -1
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
import { StyleSheet, Text, View } from "react-native";
|
|
2
|
-
import { Button } from "../button/Button";
|
|
3
|
-
import { useTheme } from "../../contexts/ThemeContext";
|
|
4
|
-
import { cardStyle, resolveTheme } from "../../helpers/themeStyles";
|
|
5
|
-
import { SPACE } from "../../helpers/layout";
|
|
6
|
-
|
|
7
|
-
export type VisionSuggestion = {
|
|
8
|
-
kind: string;
|
|
9
|
-
rank: number;
|
|
10
|
-
title: string;
|
|
11
|
-
body: string;
|
|
12
|
-
payload?: Record<string, unknown>;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type VisionActionCardProps = {
|
|
16
|
-
suggestions: VisionSuggestion[];
|
|
17
|
-
primaryLabel: string | null;
|
|
18
|
-
confidence: number | null;
|
|
19
|
-
requireConfirm: boolean;
|
|
20
|
-
onConfirm: () => void;
|
|
21
|
-
onRetake: () => void;
|
|
22
|
-
onWrong: () => void;
|
|
23
|
-
busy?: boolean;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export function VisionActionCard({
|
|
27
|
-
suggestions,
|
|
28
|
-
primaryLabel,
|
|
29
|
-
confidence,
|
|
30
|
-
requireConfirm,
|
|
31
|
-
onConfirm,
|
|
32
|
-
onRetake,
|
|
33
|
-
onWrong,
|
|
34
|
-
busy,
|
|
35
|
-
}: VisionActionCardProps) {
|
|
36
|
-
const { theme } = useTheme();
|
|
37
|
-
const t = resolveTheme(theme);
|
|
38
|
-
const primary =
|
|
39
|
-
suggestions.find((s) => s.kind === "SORT_BIN") ||
|
|
40
|
-
suggestions.find((s) => s.kind === "UNSURE") ||
|
|
41
|
-
suggestions[0];
|
|
42
|
-
const pedagogy = suggestions.find((s) => s.kind === "PEDAGOGY");
|
|
43
|
-
const isUnsure = primary?.kind === "UNSURE";
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
<View style={styles.root}>
|
|
47
|
-
<Text style={[styles.kicker, { color: t.colors.muted }]}>
|
|
48
|
-
Résultat du scan
|
|
49
|
-
{primaryLabel ? ` · ${primaryLabel}` : ""}
|
|
50
|
-
{confidence != null ? ` · ${Math.round(confidence * 100)} %` : ""}
|
|
51
|
-
</Text>
|
|
52
|
-
|
|
53
|
-
{primary ? (
|
|
54
|
-
<View
|
|
55
|
-
style={[
|
|
56
|
-
cardStyle(theme),
|
|
57
|
-
styles.cardPad,
|
|
58
|
-
{
|
|
59
|
-
borderColor: isUnsure ? t.colors.error : t.colors.primary,
|
|
60
|
-
borderWidth: 1.5,
|
|
61
|
-
},
|
|
62
|
-
]}
|
|
63
|
-
>
|
|
64
|
-
<Text style={[styles.title, { color: t.colors.onSurface }]}>
|
|
65
|
-
{primary.title}
|
|
66
|
-
</Text>
|
|
67
|
-
<Text style={[styles.body, { color: t.colors.muted }]}>{primary.body}</Text>
|
|
68
|
-
</View>
|
|
69
|
-
) : null}
|
|
70
|
-
|
|
71
|
-
{pedagogy ? (
|
|
72
|
-
<View style={styles.pedagogy}>
|
|
73
|
-
<Text style={[styles.title, { color: t.colors.onSurface }]}>
|
|
74
|
-
{pedagogy.title}
|
|
75
|
-
</Text>
|
|
76
|
-
<Text style={[styles.body, { color: t.colors.muted }]}>{pedagogy.body}</Text>
|
|
77
|
-
</View>
|
|
78
|
-
) : null}
|
|
79
|
-
|
|
80
|
-
<View style={styles.row}>
|
|
81
|
-
<Button variant="outline" onPress={onRetake} disabled={busy} style={styles.flexBtn}>
|
|
82
|
-
Reprendre
|
|
83
|
-
</Button>
|
|
84
|
-
<Button
|
|
85
|
-
variant="outline"
|
|
86
|
-
onPress={onWrong}
|
|
87
|
-
disabled={busy}
|
|
88
|
-
style={styles.flexBtn}
|
|
89
|
-
textStyle={{ color: t.colors.error }}
|
|
90
|
-
>
|
|
91
|
-
Ce n’est pas ça
|
|
92
|
-
</Button>
|
|
93
|
-
{!isUnsure && requireConfirm ? (
|
|
94
|
-
<Button
|
|
95
|
-
onPress={onConfirm}
|
|
96
|
-
disabled={busy}
|
|
97
|
-
loading={busy}
|
|
98
|
-
style={styles.flexBtn}
|
|
99
|
-
>
|
|
100
|
-
Confirmer
|
|
101
|
-
</Button>
|
|
102
|
-
) : null}
|
|
103
|
-
</View>
|
|
104
|
-
</View>
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const styles = StyleSheet.create({
|
|
109
|
-
root: { gap: 14 },
|
|
110
|
-
kicker: { fontSize: 13 },
|
|
111
|
-
cardPad: { padding: SPACE.cardPad, gap: 6 },
|
|
112
|
-
pedagogy: { gap: 4 },
|
|
113
|
-
title: { fontSize: 18, fontWeight: "700" },
|
|
114
|
-
body: { fontSize: 15, lineHeight: 22 },
|
|
115
|
-
row: { flexDirection: "row", flexWrap: "wrap", gap: 8 },
|
|
116
|
-
flexBtn: { flexGrow: 1, minWidth: 100 },
|
|
117
|
-
});
|
|
1
|
+
import { StyleSheet, Text, View } from "react-native";
|
|
2
|
+
import { Button } from "../button/Button";
|
|
3
|
+
import { useTheme } from "../../contexts/ThemeContext";
|
|
4
|
+
import { cardStyle, resolveTheme } from "../../helpers/themeStyles";
|
|
5
|
+
import { SPACE } from "../../helpers/layout";
|
|
6
|
+
|
|
7
|
+
export type VisionSuggestion = {
|
|
8
|
+
kind: string;
|
|
9
|
+
rank: number;
|
|
10
|
+
title: string;
|
|
11
|
+
body: string;
|
|
12
|
+
payload?: Record<string, unknown>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type VisionActionCardProps = {
|
|
16
|
+
suggestions: VisionSuggestion[];
|
|
17
|
+
primaryLabel: string | null;
|
|
18
|
+
confidence: number | null;
|
|
19
|
+
requireConfirm: boolean;
|
|
20
|
+
onConfirm: () => void;
|
|
21
|
+
onRetake: () => void;
|
|
22
|
+
onWrong: () => void;
|
|
23
|
+
busy?: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export function VisionActionCard({
|
|
27
|
+
suggestions,
|
|
28
|
+
primaryLabel,
|
|
29
|
+
confidence,
|
|
30
|
+
requireConfirm,
|
|
31
|
+
onConfirm,
|
|
32
|
+
onRetake,
|
|
33
|
+
onWrong,
|
|
34
|
+
busy,
|
|
35
|
+
}: VisionActionCardProps) {
|
|
36
|
+
const { theme } = useTheme();
|
|
37
|
+
const t = resolveTheme(theme);
|
|
38
|
+
const primary =
|
|
39
|
+
suggestions.find((s) => s.kind === "SORT_BIN") ||
|
|
40
|
+
suggestions.find((s) => s.kind === "UNSURE") ||
|
|
41
|
+
suggestions[0];
|
|
42
|
+
const pedagogy = suggestions.find((s) => s.kind === "PEDAGOGY");
|
|
43
|
+
const isUnsure = primary?.kind === "UNSURE";
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<View style={styles.root}>
|
|
47
|
+
<Text style={[styles.kicker, { color: t.colors.muted }]}>
|
|
48
|
+
Résultat du scan
|
|
49
|
+
{primaryLabel ? ` · ${primaryLabel}` : ""}
|
|
50
|
+
{confidence != null ? ` · ${Math.round(confidence * 100)} %` : ""}
|
|
51
|
+
</Text>
|
|
52
|
+
|
|
53
|
+
{primary ? (
|
|
54
|
+
<View
|
|
55
|
+
style={[
|
|
56
|
+
cardStyle(theme),
|
|
57
|
+
styles.cardPad,
|
|
58
|
+
{
|
|
59
|
+
borderColor: isUnsure ? t.colors.error : t.colors.primary,
|
|
60
|
+
borderWidth: 1.5,
|
|
61
|
+
},
|
|
62
|
+
]}
|
|
63
|
+
>
|
|
64
|
+
<Text style={[styles.title, { color: t.colors.onSurface }]}>
|
|
65
|
+
{primary.title}
|
|
66
|
+
</Text>
|
|
67
|
+
<Text style={[styles.body, { color: t.colors.muted }]}>{primary.body}</Text>
|
|
68
|
+
</View>
|
|
69
|
+
) : null}
|
|
70
|
+
|
|
71
|
+
{pedagogy ? (
|
|
72
|
+
<View style={styles.pedagogy}>
|
|
73
|
+
<Text style={[styles.title, { color: t.colors.onSurface }]}>
|
|
74
|
+
{pedagogy.title}
|
|
75
|
+
</Text>
|
|
76
|
+
<Text style={[styles.body, { color: t.colors.muted }]}>{pedagogy.body}</Text>
|
|
77
|
+
</View>
|
|
78
|
+
) : null}
|
|
79
|
+
|
|
80
|
+
<View style={styles.row}>
|
|
81
|
+
<Button variant="outline" onPress={onRetake} disabled={busy} style={styles.flexBtn}>
|
|
82
|
+
Reprendre
|
|
83
|
+
</Button>
|
|
84
|
+
<Button
|
|
85
|
+
variant="outline"
|
|
86
|
+
onPress={onWrong}
|
|
87
|
+
disabled={busy}
|
|
88
|
+
style={styles.flexBtn}
|
|
89
|
+
textStyle={{ color: t.colors.error }}
|
|
90
|
+
>
|
|
91
|
+
Ce n’est pas ça
|
|
92
|
+
</Button>
|
|
93
|
+
{!isUnsure && requireConfirm ? (
|
|
94
|
+
<Button
|
|
95
|
+
onPress={onConfirm}
|
|
96
|
+
disabled={busy}
|
|
97
|
+
loading={busy}
|
|
98
|
+
style={styles.flexBtn}
|
|
99
|
+
>
|
|
100
|
+
Confirmer
|
|
101
|
+
</Button>
|
|
102
|
+
) : null}
|
|
103
|
+
</View>
|
|
104
|
+
</View>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const styles = StyleSheet.create({
|
|
109
|
+
root: { gap: 14 },
|
|
110
|
+
kicker: { fontSize: 13 },
|
|
111
|
+
cardPad: { padding: SPACE.cardPad, gap: 6 },
|
|
112
|
+
pedagogy: { gap: 4 },
|
|
113
|
+
title: { fontSize: 18, fontWeight: "700" },
|
|
114
|
+
body: { fontSize: 15, lineHeight: 22 },
|
|
115
|
+
row: { flexDirection: "row", flexWrap: "wrap", gap: 8 },
|
|
116
|
+
flexBtn: { flexGrow: 1, minWidth: 100 },
|
|
117
|
+
});
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { StyleSheet, Text, View } from "react-native";
|
|
2
|
-
import { Button } from "../button/Button";
|
|
3
|
-
import { useTheme } from "../../contexts/ThemeContext";
|
|
4
|
-
import { resolveTheme } from "../../helpers/themeStyles";
|
|
5
|
-
import { SPACE } from "../../helpers/layout";
|
|
6
|
-
|
|
7
|
-
export type VisionCaptureProps = {
|
|
8
|
-
tips: string;
|
|
9
|
-
onCapture: () => void;
|
|
10
|
-
busy?: boolean;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export function VisionCapture({ tips, onCapture, busy }: VisionCaptureProps) {
|
|
14
|
-
const { theme } = useTheme();
|
|
15
|
-
const t = resolveTheme(theme);
|
|
16
|
-
|
|
17
|
-
return (
|
|
18
|
-
<View style={styles.root}>
|
|
19
|
-
<Text style={[styles.tips, { color: t.colors.muted }]}>{tips}</Text>
|
|
20
|
-
<Button onPress={onCapture} disabled={busy} loading={busy}>
|
|
21
|
-
{busy ? "Ouverture…" : "Prendre une photo"}
|
|
22
|
-
</Button>
|
|
23
|
-
</View>
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const styles = StyleSheet.create({
|
|
28
|
-
root: { gap: SPACE.stack },
|
|
29
|
-
tips: { fontSize: 14, lineHeight: 20 },
|
|
30
|
-
});
|
|
1
|
+
import { StyleSheet, Text, View } from "react-native";
|
|
2
|
+
import { Button } from "../button/Button";
|
|
3
|
+
import { useTheme } from "../../contexts/ThemeContext";
|
|
4
|
+
import { resolveTheme } from "../../helpers/themeStyles";
|
|
5
|
+
import { SPACE } from "../../helpers/layout";
|
|
6
|
+
|
|
7
|
+
export type VisionCaptureProps = {
|
|
8
|
+
tips: string;
|
|
9
|
+
onCapture: () => void;
|
|
10
|
+
busy?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function VisionCapture({ tips, onCapture, busy }: VisionCaptureProps) {
|
|
14
|
+
const { theme } = useTheme();
|
|
15
|
+
const t = resolveTheme(theme);
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<View style={styles.root}>
|
|
19
|
+
<Text style={[styles.tips, { color: t.colors.muted }]}>{tips}</Text>
|
|
20
|
+
<Button onPress={onCapture} disabled={busy} loading={busy}>
|
|
21
|
+
{busy ? "Ouverture…" : "Prendre une photo"}
|
|
22
|
+
</Button>
|
|
23
|
+
</View>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const styles = StyleSheet.create({
|
|
28
|
+
root: { gap: SPACE.stack },
|
|
29
|
+
tips: { fontSize: 14, lineHeight: 20 },
|
|
30
|
+
});
|
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
import { useCallback, useState } from "react";
|
|
2
|
-
import {
|
|
3
|
-
LayoutChangeEvent,
|
|
4
|
-
Pressable,
|
|
5
|
-
StyleSheet,
|
|
6
|
-
Text,
|
|
7
|
-
View,
|
|
8
|
-
} from "react-native";
|
|
9
|
-
import { Image } from "expo-image";
|
|
10
|
-
import { Button } from "../button/Button";
|
|
11
|
-
import { useTheme } from "../../contexts/ThemeContext";
|
|
12
|
-
import { resolveTheme } from "../../helpers/themeStyles";
|
|
13
|
-
import { SPACE } from "../../helpers/layout";
|
|
14
|
-
|
|
15
|
-
export type VisionTapOverlayProps = {
|
|
16
|
-
imageUri: string;
|
|
17
|
-
tap: { x: number; y: number } | null;
|
|
18
|
-
onTap: (tap: { x: number; y: number }) => void;
|
|
19
|
-
onAnalyzeFull: () => void;
|
|
20
|
-
onConfirmTap: () => void;
|
|
21
|
-
onRetake: () => void;
|
|
22
|
-
busy?: boolean;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export function VisionTapOverlay({
|
|
26
|
-
imageUri,
|
|
27
|
-
tap,
|
|
28
|
-
onTap,
|
|
29
|
-
onAnalyzeFull,
|
|
30
|
-
onConfirmTap,
|
|
31
|
-
onRetake,
|
|
32
|
-
busy,
|
|
33
|
-
}: VisionTapOverlayProps) {
|
|
34
|
-
const { theme } = useTheme();
|
|
35
|
-
const t = resolveTheme(theme);
|
|
36
|
-
const [size, setSize] = useState({ w: 1, h: 1 });
|
|
37
|
-
|
|
38
|
-
const onLayout = useCallback((e: LayoutChangeEvent) => {
|
|
39
|
-
const { width, height } = e.nativeEvent.layout;
|
|
40
|
-
setSize({ w: Math.max(width, 1), h: Math.max(height, 1) });
|
|
41
|
-
}, []);
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<View style={styles.root}>
|
|
45
|
-
<Text style={[styles.hint, { color: t.colors.muted }]}>
|
|
46
|
-
Touchez le déchet sur la photo, ou analysez toute l’image.
|
|
47
|
-
</Text>
|
|
48
|
-
<Pressable
|
|
49
|
-
onLayout={onLayout}
|
|
50
|
-
onPress={(ev) => {
|
|
51
|
-
const { locationX, locationY } = ev.nativeEvent;
|
|
52
|
-
onTap({
|
|
53
|
-
x: Math.min(1, Math.max(0, locationX / size.w)),
|
|
54
|
-
y: Math.min(1, Math.max(0, locationY / size.h)),
|
|
55
|
-
});
|
|
56
|
-
}}
|
|
57
|
-
style={[
|
|
58
|
-
styles.imageWrap,
|
|
59
|
-
{ borderRadius: t.radii.md, backgroundColor: t.colors.onSurface },
|
|
60
|
-
]}
|
|
61
|
-
>
|
|
62
|
-
<Image source={{ uri: imageUri }} style={styles.image} contentFit="contain" />
|
|
63
|
-
{tap ? (
|
|
64
|
-
<View
|
|
65
|
-
pointerEvents="none"
|
|
66
|
-
style={[
|
|
67
|
-
styles.halo,
|
|
68
|
-
{
|
|
69
|
-
left: tap.x * size.w - 18,
|
|
70
|
-
top: tap.y * size.h - 18,
|
|
71
|
-
borderColor: t.colors.primary,
|
|
72
|
-
},
|
|
73
|
-
]}
|
|
74
|
-
/>
|
|
75
|
-
) : null}
|
|
76
|
-
</Pressable>
|
|
77
|
-
|
|
78
|
-
<View style={styles.row}>
|
|
79
|
-
<Button variant="outline" onPress={onRetake} disabled={busy} style={styles.flexBtn}>
|
|
80
|
-
Reprendre
|
|
81
|
-
</Button>
|
|
82
|
-
<Button
|
|
83
|
-
variant="secondary"
|
|
84
|
-
onPress={onAnalyzeFull}
|
|
85
|
-
disabled={busy}
|
|
86
|
-
style={styles.flexBtn}
|
|
87
|
-
>
|
|
88
|
-
Toute l’image
|
|
89
|
-
</Button>
|
|
90
|
-
<Button
|
|
91
|
-
onPress={onConfirmTap}
|
|
92
|
-
disabled={!tap || busy}
|
|
93
|
-
loading={busy}
|
|
94
|
-
style={styles.flexBtn}
|
|
95
|
-
>
|
|
96
|
-
Analyser
|
|
97
|
-
</Button>
|
|
98
|
-
</View>
|
|
99
|
-
</View>
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const styles = StyleSheet.create({
|
|
104
|
-
root: { gap: SPACE.stack, flex: 1 },
|
|
105
|
-
hint: { fontSize: 14, lineHeight: 20 },
|
|
106
|
-
imageWrap: {
|
|
107
|
-
flex: 1,
|
|
108
|
-
minHeight: 280,
|
|
109
|
-
overflow: "hidden",
|
|
110
|
-
},
|
|
111
|
-
image: { width: "100%", height: "100%" },
|
|
112
|
-
halo: {
|
|
113
|
-
position: "absolute",
|
|
114
|
-
width: 36,
|
|
115
|
-
height: 36,
|
|
116
|
-
borderRadius: 18,
|
|
117
|
-
borderWidth: 3,
|
|
118
|
-
backgroundColor: "rgba(255,255,255,0.25)",
|
|
119
|
-
},
|
|
120
|
-
row: { flexDirection: "row", flexWrap: "wrap", gap: 8 },
|
|
121
|
-
flexBtn: { flexGrow: 1, minWidth: 100 },
|
|
122
|
-
});
|
|
1
|
+
import { useCallback, useState } from "react";
|
|
2
|
+
import {
|
|
3
|
+
LayoutChangeEvent,
|
|
4
|
+
Pressable,
|
|
5
|
+
StyleSheet,
|
|
6
|
+
Text,
|
|
7
|
+
View,
|
|
8
|
+
} from "react-native";
|
|
9
|
+
import { Image } from "expo-image";
|
|
10
|
+
import { Button } from "../button/Button";
|
|
11
|
+
import { useTheme } from "../../contexts/ThemeContext";
|
|
12
|
+
import { resolveTheme } from "../../helpers/themeStyles";
|
|
13
|
+
import { SPACE } from "../../helpers/layout";
|
|
14
|
+
|
|
15
|
+
export type VisionTapOverlayProps = {
|
|
16
|
+
imageUri: string;
|
|
17
|
+
tap: { x: number; y: number } | null;
|
|
18
|
+
onTap: (tap: { x: number; y: number }) => void;
|
|
19
|
+
onAnalyzeFull: () => void;
|
|
20
|
+
onConfirmTap: () => void;
|
|
21
|
+
onRetake: () => void;
|
|
22
|
+
busy?: boolean;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function VisionTapOverlay({
|
|
26
|
+
imageUri,
|
|
27
|
+
tap,
|
|
28
|
+
onTap,
|
|
29
|
+
onAnalyzeFull,
|
|
30
|
+
onConfirmTap,
|
|
31
|
+
onRetake,
|
|
32
|
+
busy,
|
|
33
|
+
}: VisionTapOverlayProps) {
|
|
34
|
+
const { theme } = useTheme();
|
|
35
|
+
const t = resolveTheme(theme);
|
|
36
|
+
const [size, setSize] = useState({ w: 1, h: 1 });
|
|
37
|
+
|
|
38
|
+
const onLayout = useCallback((e: LayoutChangeEvent) => {
|
|
39
|
+
const { width, height } = e.nativeEvent.layout;
|
|
40
|
+
setSize({ w: Math.max(width, 1), h: Math.max(height, 1) });
|
|
41
|
+
}, []);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<View style={styles.root}>
|
|
45
|
+
<Text style={[styles.hint, { color: t.colors.muted }]}>
|
|
46
|
+
Touchez le déchet sur la photo, ou analysez toute l’image.
|
|
47
|
+
</Text>
|
|
48
|
+
<Pressable
|
|
49
|
+
onLayout={onLayout}
|
|
50
|
+
onPress={(ev) => {
|
|
51
|
+
const { locationX, locationY } = ev.nativeEvent;
|
|
52
|
+
onTap({
|
|
53
|
+
x: Math.min(1, Math.max(0, locationX / size.w)),
|
|
54
|
+
y: Math.min(1, Math.max(0, locationY / size.h)),
|
|
55
|
+
});
|
|
56
|
+
}}
|
|
57
|
+
style={[
|
|
58
|
+
styles.imageWrap,
|
|
59
|
+
{ borderRadius: t.radii.md, backgroundColor: t.colors.onSurface },
|
|
60
|
+
]}
|
|
61
|
+
>
|
|
62
|
+
<Image source={{ uri: imageUri }} style={styles.image} contentFit="contain" />
|
|
63
|
+
{tap ? (
|
|
64
|
+
<View
|
|
65
|
+
pointerEvents="none"
|
|
66
|
+
style={[
|
|
67
|
+
styles.halo,
|
|
68
|
+
{
|
|
69
|
+
left: tap.x * size.w - 18,
|
|
70
|
+
top: tap.y * size.h - 18,
|
|
71
|
+
borderColor: t.colors.primary,
|
|
72
|
+
},
|
|
73
|
+
]}
|
|
74
|
+
/>
|
|
75
|
+
) : null}
|
|
76
|
+
</Pressable>
|
|
77
|
+
|
|
78
|
+
<View style={styles.row}>
|
|
79
|
+
<Button variant="outline" onPress={onRetake} disabled={busy} style={styles.flexBtn}>
|
|
80
|
+
Reprendre
|
|
81
|
+
</Button>
|
|
82
|
+
<Button
|
|
83
|
+
variant="secondary"
|
|
84
|
+
onPress={onAnalyzeFull}
|
|
85
|
+
disabled={busy}
|
|
86
|
+
style={styles.flexBtn}
|
|
87
|
+
>
|
|
88
|
+
Toute l’image
|
|
89
|
+
</Button>
|
|
90
|
+
<Button
|
|
91
|
+
onPress={onConfirmTap}
|
|
92
|
+
disabled={!tap || busy}
|
|
93
|
+
loading={busy}
|
|
94
|
+
style={styles.flexBtn}
|
|
95
|
+
>
|
|
96
|
+
Analyser
|
|
97
|
+
</Button>
|
|
98
|
+
</View>
|
|
99
|
+
</View>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const styles = StyleSheet.create({
|
|
104
|
+
root: { gap: SPACE.stack, flex: 1 },
|
|
105
|
+
hint: { fontSize: 14, lineHeight: 20 },
|
|
106
|
+
imageWrap: {
|
|
107
|
+
flex: 1,
|
|
108
|
+
minHeight: 280,
|
|
109
|
+
overflow: "hidden",
|
|
110
|
+
},
|
|
111
|
+
image: { width: "100%", height: "100%" },
|
|
112
|
+
halo: {
|
|
113
|
+
position: "absolute",
|
|
114
|
+
width: 36,
|
|
115
|
+
height: 36,
|
|
116
|
+
borderRadius: 18,
|
|
117
|
+
borderWidth: 3,
|
|
118
|
+
backgroundColor: "rgba(255,255,255,0.25)",
|
|
119
|
+
},
|
|
120
|
+
row: { flexDirection: "row", flexWrap: "wrap", gap: 8 },
|
|
121
|
+
flexBtn: { flexGrow: 1, minWidth: 100 },
|
|
122
|
+
});
|