@towsila/expo-ui-library 4.3.1 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/ui/circularCountdown.tsx +104 -0
- package/src/components/ui/requestCard.tsx +212 -0
- package/src/index.ts +3 -1
- package/src/types/request.ts +13 -0
package/package.json
CHANGED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { Text, View } from "react-native";
|
|
3
|
+
import Svg, { Circle, Path } from "react-native-svg";
|
|
4
|
+
import { useLanguage } from "../../context/LanguageContext";
|
|
5
|
+
import { useAppTheme } from "../../context/ThemeContext";
|
|
6
|
+
import { Fonts, textSize } from "../../tokens/typography";
|
|
7
|
+
|
|
8
|
+
const DURATION = 120; // seconds
|
|
9
|
+
const SIZE = 23;
|
|
10
|
+
const CENTER = SIZE / 2;
|
|
11
|
+
const RADIUS = CENTER - 1.5;
|
|
12
|
+
|
|
13
|
+
function getPiePath(progress: number) {
|
|
14
|
+
if (progress <= 0) return "";
|
|
15
|
+
if (progress >= 1) {
|
|
16
|
+
return [
|
|
17
|
+
`M ${CENTER} ${CENTER}`,
|
|
18
|
+
`m 0 ${-RADIUS}`,
|
|
19
|
+
`a ${RADIUS} ${RADIUS} 0 1 1 0 ${2 * RADIUS}`,
|
|
20
|
+
`a ${RADIUS} ${RADIUS} 0 1 1 0 ${-2 * RADIUS}`,
|
|
21
|
+
"Z",
|
|
22
|
+
].join(" ");
|
|
23
|
+
}
|
|
24
|
+
const angle = progress * 2 * Math.PI - Math.PI / 2;
|
|
25
|
+
const x = CENTER + RADIUS * Math.cos(angle);
|
|
26
|
+
const y = CENTER + RADIUS * Math.sin(angle);
|
|
27
|
+
const largeArc = progress > 0.5 ? 1 : 0;
|
|
28
|
+
return [
|
|
29
|
+
`M ${CENTER} ${CENTER}`,
|
|
30
|
+
`L ${CENTER} ${CENTER - RADIUS}`,
|
|
31
|
+
`A ${RADIUS} ${RADIUS} 0 ${largeArc} 1 ${x} ${y}`,
|
|
32
|
+
"Z",
|
|
33
|
+
].join(" ");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const secondsLeft = (deadline: number) =>
|
|
37
|
+
Math.max(0, Math.ceil((deadline - Date.now()) / 1000));
|
|
38
|
+
|
|
39
|
+
export default function CircularCountdown({
|
|
40
|
+
deadline,
|
|
41
|
+
onExpire,
|
|
42
|
+
}: {
|
|
43
|
+
deadline: number;
|
|
44
|
+
onExpire?: () => void;
|
|
45
|
+
}) {
|
|
46
|
+
const { colors } = useAppTheme();
|
|
47
|
+
// const [remaining, setRemaining] = useState(() => secondsLeft(deadline));
|
|
48
|
+
// const fired = useRef(false);
|
|
49
|
+
const {isRTL} = useLanguage();
|
|
50
|
+
|
|
51
|
+
// ONLY FOR TESTING
|
|
52
|
+
const testDeadline = useRef(Date.now() + DURATION * 1000).current;
|
|
53
|
+
const target = testDeadline;
|
|
54
|
+
const [remaining, setRemaining] = useState(() => secondsLeft(target));
|
|
55
|
+
const fired = useRef(false);
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
// CHANGE TARGET TO DEADLINE
|
|
59
|
+
setRemaining(secondsLeft(target));
|
|
60
|
+
const id = setInterval(() => setRemaining(secondsLeft(target)), 1000);
|
|
61
|
+
return () => clearInterval(id);
|
|
62
|
+
}, [target]);
|
|
63
|
+
|
|
64
|
+
// fire once when it reaches 00:00
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (remaining === 0 && !fired.current) {
|
|
67
|
+
fired.current = true;
|
|
68
|
+
onExpire?.();
|
|
69
|
+
}
|
|
70
|
+
}, [remaining]);
|
|
71
|
+
|
|
72
|
+
const progress = Math.min(remaining / DURATION, 1);
|
|
73
|
+
const timerColor = remaining <= 30 ? colors.semantic.error : colors.semantic.warning;
|
|
74
|
+
|
|
75
|
+
const mm = String(Math.floor(remaining / 60)).padStart(2, "0");
|
|
76
|
+
const ss = String(remaining % 60).padStart(2, "0");
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<View style={{ flexDirection: isRTL ? "row-reverse" :"row", alignItems: "center", gap: 6 }}>
|
|
80
|
+
<Text
|
|
81
|
+
style={{
|
|
82
|
+
fontFamily: Fonts.montserrat.regular,
|
|
83
|
+
fontSize: textSize.xs,
|
|
84
|
+
color: colors.text.primary,
|
|
85
|
+
fontVariant: ["tabular-nums"], // digits keep the same width, no jitter
|
|
86
|
+
}}
|
|
87
|
+
>
|
|
88
|
+
{`${mm}:${ss}`}
|
|
89
|
+
</Text>
|
|
90
|
+
<Svg width={SIZE} height={SIZE} viewBox={`0 0 ${SIZE} ${SIZE}`}>
|
|
91
|
+
<Path d={getPiePath(progress)} fill={timerColor} />
|
|
92
|
+
<Circle cx={CENTER} cy={CENTER} r={RADIUS} fill="none" stroke={colors.primary} strokeWidth={1.5} />
|
|
93
|
+
<Circle
|
|
94
|
+
cx={CENTER}
|
|
95
|
+
cy={CENTER}
|
|
96
|
+
r={RADIUS}
|
|
97
|
+
fill="none"
|
|
98
|
+
stroke={timerColor}
|
|
99
|
+
strokeWidth={1.5}
|
|
100
|
+
/>
|
|
101
|
+
</Svg>
|
|
102
|
+
</View>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { View, Text } from "react-native";
|
|
2
|
+
import Clock from "@/assets/images/icons/clock.svg";
|
|
3
|
+
import Destination from "@/assets/images/icons/destination.svg";
|
|
4
|
+
import Flag from "@/assets/images/icons/flag.svg";
|
|
5
|
+
import Warning from "@/assets/images/icons/warning.svg";
|
|
6
|
+
import { SvgProps } from "react-native-svg";
|
|
7
|
+
import { useAppTheme } from "../../context/ThemeContext";
|
|
8
|
+
import { useRelativeTime } from "../../hooks/useRelativeTime";
|
|
9
|
+
import { useLanguage } from "../../context/LanguageContext";
|
|
10
|
+
import {Request} from "../../types/request";
|
|
11
|
+
import { Fonts, textSize } from "../../tokens/typography";
|
|
12
|
+
import CircularCountdown from "./circularCountdown";
|
|
13
|
+
import { formatPrice } from "../../utils/formatPrice";
|
|
14
|
+
export default function RequestCard({
|
|
15
|
+
request,
|
|
16
|
+
addRow = false,
|
|
17
|
+
onExpire,
|
|
18
|
+
t,
|
|
19
|
+
locationName,
|
|
20
|
+
destinationName,
|
|
21
|
+
}: { request: Request, addRow?: boolean, onExpire?: (id:string)=>void, t: (key: string, opts?: any) => string; locationName: string; destinationName: string;}) {
|
|
22
|
+
const {colors} = useAppTheme();
|
|
23
|
+
const formatRelative = useRelativeTime(t);
|
|
24
|
+
const {isRTL} = useLanguage();
|
|
25
|
+
const statusColors = {
|
|
26
|
+
PENDING: colors.semantic.warning,
|
|
27
|
+
CONFIRMED: colors.semantic.success,
|
|
28
|
+
REJECTED: colors.semantic.error,
|
|
29
|
+
CANCELLED: colors.text.placeholder,
|
|
30
|
+
AWAITING_PICK_UP: colors.semantic.warning,
|
|
31
|
+
PICK_UP:colors.semantic.warning,
|
|
32
|
+
DROP_OFF:colors.semantic.warning,
|
|
33
|
+
EXPIRED: colors.text.placeholder,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const statusLabels = {
|
|
37
|
+
PENDING: t("request.status.PENDING"),
|
|
38
|
+
CONFIRMED: t("request.status.CONFIRMED"),
|
|
39
|
+
REJECTED: t("request.status.REJECTED"),
|
|
40
|
+
CANCELLED: t("request.status.CANCELLED"),
|
|
41
|
+
AWAITING_PICK_UP:t("request.status.AWAITING_PICK_UP"),
|
|
42
|
+
PICK_UP:t("request.status.PICK_UP"),
|
|
43
|
+
DROP_OFF:t("request.status.DROP_OFF"),
|
|
44
|
+
EXPIRED: t("request.status.EXPIRED")
|
|
45
|
+
};
|
|
46
|
+
const result = t("request.time.ago", { time: formatRelative(request.time) });
|
|
47
|
+
|
|
48
|
+
// const locationName = shortAddress(usePlaceName(request.location)); // [lat, lng]
|
|
49
|
+
// const destinationName =shortAddress(usePlaceName(request.destination));
|
|
50
|
+
const carStateText = request.carState
|
|
51
|
+
.map((s) => t(`request.carStateEnum.${s}`))
|
|
52
|
+
.join(" - ");
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
const deadline = new Date(request.time).getTime() + 2 * 60 * 1000;
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<View
|
|
59
|
+
style={{
|
|
60
|
+
backgroundColor: colors.background.card,
|
|
61
|
+
borderRadius: 15,
|
|
62
|
+
padding: 12,
|
|
63
|
+
// marginBottom: 0,
|
|
64
|
+
borderWidth: 1.5,
|
|
65
|
+
borderColor: colors.text.primary,
|
|
66
|
+
gap: 10
|
|
67
|
+
}}
|
|
68
|
+
>
|
|
69
|
+
<View style={{gap: 5}}>
|
|
70
|
+
<View style={{
|
|
71
|
+
flexDirection: isRTL ?"row":"row-reverse",
|
|
72
|
+
justifyContent: "space-between",
|
|
73
|
+
}}>
|
|
74
|
+
<Text
|
|
75
|
+
style={{
|
|
76
|
+
fontSize: textSize.lg,
|
|
77
|
+
fontFamily: Fonts.montserrat.bold,
|
|
78
|
+
color: colors.text.primary,
|
|
79
|
+
}}
|
|
80
|
+
>
|
|
81
|
+
{request.name}
|
|
82
|
+
</Text>
|
|
83
|
+
<View
|
|
84
|
+
style={{
|
|
85
|
+
backgroundColor: statusColors[request.status] + "20",
|
|
86
|
+
paddingHorizontal: 10,
|
|
87
|
+
paddingVertical: 4,
|
|
88
|
+
borderRadius: 20,
|
|
89
|
+
}}
|
|
90
|
+
>
|
|
91
|
+
<Text
|
|
92
|
+
style={{
|
|
93
|
+
fontSize: textSize.sm,
|
|
94
|
+
fontFamily: Fonts.montserrat.regular,
|
|
95
|
+
color: statusColors[request.status],
|
|
96
|
+
}}
|
|
97
|
+
>
|
|
98
|
+
{statusLabels[request.status]}
|
|
99
|
+
</Text>
|
|
100
|
+
</View>
|
|
101
|
+
</View>
|
|
102
|
+
{addRow && (
|
|
103
|
+
<View style={{
|
|
104
|
+
flexDirection: isRTL ?"row":"row-reverse",
|
|
105
|
+
justifyContent: "space-between",
|
|
106
|
+
alignItems: "center",
|
|
107
|
+
}}>
|
|
108
|
+
<Text style={{
|
|
109
|
+
fontSize: textSize.xs,
|
|
110
|
+
fontFamily: Fonts.montserrat.regular,
|
|
111
|
+
color:colors.text.secondary
|
|
112
|
+
}}>
|
|
113
|
+
{request.phone} · {t(`request.vehicleType.${request.vehicleType}`)}
|
|
114
|
+
</Text>
|
|
115
|
+
{request.status === "PENDING" ? (
|
|
116
|
+
<CircularCountdown deadline={deadline} onExpire={() => onExpire?.(request.id)}/>
|
|
117
|
+
):(
|
|
118
|
+
<View style={{flexDirection: isRTL ?"row":"row-reverse", alignItems: "center", gap: 4}}>
|
|
119
|
+
<View style={[isRTL && {transform :[{scaleX:-1}]}]}>
|
|
120
|
+
<Clock width={13} height={13} color={colors.text.placeholder} />
|
|
121
|
+
</View>
|
|
122
|
+
<Text
|
|
123
|
+
style={{
|
|
124
|
+
fontSize: textSize.xs,
|
|
125
|
+
fontFamily: Fonts.montserrat.regular,
|
|
126
|
+
color: colors.text.placeholder,
|
|
127
|
+
}}
|
|
128
|
+
>
|
|
129
|
+
{result}
|
|
130
|
+
</Text>
|
|
131
|
+
</View>
|
|
132
|
+
)}
|
|
133
|
+
|
|
134
|
+
</View>
|
|
135
|
+
)}
|
|
136
|
+
</View>
|
|
137
|
+
<CardRow icon={Destination} label={t("request.pickUp")} value={locationName}/>
|
|
138
|
+
<CardRow icon={Flag} label={t("request.destination")} value={destinationName}/>
|
|
139
|
+
<CardRow icon={Warning} label={t("request.carState")} value={carStateText}/>
|
|
140
|
+
<View style={{borderWidth:0.5, borderColor: colors.semantic.border}}/>
|
|
141
|
+
<View
|
|
142
|
+
style={{
|
|
143
|
+
flexDirection: isRTL ? "row" : "row-reverse",
|
|
144
|
+
justifyContent: "space-between",
|
|
145
|
+
gap: 10,
|
|
146
|
+
}}
|
|
147
|
+
>
|
|
148
|
+
<Text
|
|
149
|
+
style={{
|
|
150
|
+
color: colors.text.secondary,
|
|
151
|
+
fontSize: textSize.sm,
|
|
152
|
+
fontFamily: Fonts.montserrat.regular,
|
|
153
|
+
}}
|
|
154
|
+
>
|
|
155
|
+
{t("request.total")}
|
|
156
|
+
</Text>
|
|
157
|
+
<Text
|
|
158
|
+
style={[
|
|
159
|
+
{
|
|
160
|
+
color: colors.text.primary,
|
|
161
|
+
fontSize: textSize.md,
|
|
162
|
+
fontFamily: Fonts.montserrat.semiBold,
|
|
163
|
+
},
|
|
164
|
+
]}
|
|
165
|
+
>
|
|
166
|
+
{`${formatPrice(request.price)} ${t("request.price.unit")}`}
|
|
167
|
+
</Text>
|
|
168
|
+
</View>
|
|
169
|
+
</View>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function CardRow({ icon: Icon, label, value }: { icon: React.ComponentType<SvgProps>; label: string; value: string }) {
|
|
174
|
+
const { isRTL } = useLanguage();
|
|
175
|
+
const { colors } = useAppTheme();
|
|
176
|
+
return (
|
|
177
|
+
<View
|
|
178
|
+
style={{
|
|
179
|
+
flexDirection: isRTL ? "row" : "row-reverse",
|
|
180
|
+
alignItems: "center",
|
|
181
|
+
gap: 10,
|
|
182
|
+
}}
|
|
183
|
+
>
|
|
184
|
+
<View style={{ flexShrink: 0 }}>
|
|
185
|
+
<Icon color={colors.primary} width={20} height={20} />
|
|
186
|
+
</View>
|
|
187
|
+
<View style={{ flex: 1 }}>
|
|
188
|
+
<Text
|
|
189
|
+
style={{
|
|
190
|
+
fontSize: textSize.sm,
|
|
191
|
+
fontFamily: Fonts.montserrat.semiBold,
|
|
192
|
+
color: colors.text.secondary,
|
|
193
|
+
textAlign: isRTL ? "left" : "right",
|
|
194
|
+
}}
|
|
195
|
+
>
|
|
196
|
+
{label}
|
|
197
|
+
</Text>
|
|
198
|
+
<Text
|
|
199
|
+
numberOfLines={2}
|
|
200
|
+
style={{
|
|
201
|
+
fontSize: textSize.sm,
|
|
202
|
+
fontFamily: Fonts.montserrat.regular,
|
|
203
|
+
color: colors.text.primary,
|
|
204
|
+
textAlign: isRTL ? "left" : "right",
|
|
205
|
+
}}
|
|
206
|
+
>
|
|
207
|
+
{value}
|
|
208
|
+
</Text>
|
|
209
|
+
</View>
|
|
210
|
+
</View>
|
|
211
|
+
);
|
|
212
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -78,4 +78,6 @@ export { formatPrice } from "./utils/formatPrice";
|
|
|
78
78
|
export { shortAddress, getWilaya } from "./utils/shortanName";
|
|
79
79
|
export {RouteInfo} from "./types/route";
|
|
80
80
|
export {default as PhonePrefix} from "./components/ui/phonePrefix";
|
|
81
|
-
export {default as ProfileScreen} from "./components/screens/profileScreen";
|
|
81
|
+
export {default as ProfileScreen} from "./components/screens/profileScreen";
|
|
82
|
+
export { default as RequestCard } from "./components/ui/requestCard";
|
|
83
|
+
export { Request, RequestStatus } from "./types/request";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type RequestStatus = "PENDING" | "CONFIRMED" | "REJECTED" | "CANCELLED" | "AWAITING_PICK_UP" | "PICK_UP" |"DROP_OFF" | "EXPIRED"
|
|
2
|
+
export type Request = {
|
|
3
|
+
id: string;
|
|
4
|
+
vehicleType: string;
|
|
5
|
+
name: string;
|
|
6
|
+
phone: string;
|
|
7
|
+
location: [number, number];
|
|
8
|
+
destination: [number, number];
|
|
9
|
+
status:RequestStatus;
|
|
10
|
+
price: number;
|
|
11
|
+
time: string;
|
|
12
|
+
carState:string[];
|
|
13
|
+
}
|