@towsila/expo-ui-library 4.3.1 → 4.4.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 +160 -0
- package/src/index.ts +3 -1
- package/src/types/request.ts +17 -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,160 @@
|
|
|
1
|
+
import { View, Text } from "react-native";
|
|
2
|
+
import { SvgProps } from "react-native-svg";
|
|
3
|
+
import Clock from "@/assets/images/icons/clock.svg";
|
|
4
|
+
import Destination from "@/assets/images/icons/destination.svg";
|
|
5
|
+
import Flag from "@/assets/images/icons/flag.svg";
|
|
6
|
+
import Warning from "@/assets/images/icons/warning.svg";
|
|
7
|
+
import { RequestCardData, RequestCardLabels } from "../../types/request";
|
|
8
|
+
import { useAppTheme } from "../../context/ThemeContext";
|
|
9
|
+
import { useLanguage } from "../../context/LanguageContext";
|
|
10
|
+
import { Fonts, textSize } from "../../tokens/typography";
|
|
11
|
+
import CircularCountdown from "./circularCountdown";
|
|
12
|
+
import { formatPrice } from "../../utils/formatPrice";
|
|
13
|
+
|
|
14
|
+
interface Props {
|
|
15
|
+
data: RequestCardData;
|
|
16
|
+
labels: RequestCardLabels;
|
|
17
|
+
statusLabel: string;
|
|
18
|
+
statusColor: string;
|
|
19
|
+
vehicleLabel: string; // already translated
|
|
20
|
+
carStateText: string; // already translated and joined
|
|
21
|
+
locationName: string;
|
|
22
|
+
destinationName: string;
|
|
23
|
+
agoText: string; // already built: "5 minutes ago"
|
|
24
|
+
showCountdown?: boolean; // true when the app considers the request pending
|
|
25
|
+
addRow?: boolean;
|
|
26
|
+
onExpire?: (id: string) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default function RequestCard({
|
|
30
|
+
data, labels, statusLabel, statusColor, vehicleLabel, carStateText,
|
|
31
|
+
locationName, destinationName, agoText,
|
|
32
|
+
showCountdown = false, addRow = false, onExpire,
|
|
33
|
+
}: Props) {
|
|
34
|
+
const { colors } = useAppTheme();
|
|
35
|
+
const { isRTL } = useLanguage();
|
|
36
|
+
const rowDir = isRTL ? "row" : "row-reverse";
|
|
37
|
+
|
|
38
|
+
const deadline = new Date(data.time).getTime() + 2 * 60 * 1000;
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<View
|
|
42
|
+
style={{
|
|
43
|
+
backgroundColor: colors.background.card,
|
|
44
|
+
borderRadius: 15,
|
|
45
|
+
padding: 12,
|
|
46
|
+
borderWidth: 1.5,
|
|
47
|
+
borderColor: colors.text.primary,
|
|
48
|
+
gap: 10,
|
|
49
|
+
}}
|
|
50
|
+
>
|
|
51
|
+
<View style={{ gap: 5 }}>
|
|
52
|
+
<View style={{ flexDirection: rowDir, justifyContent: "space-between" }}>
|
|
53
|
+
<Text style={{ fontSize: textSize.lg, fontFamily: Fonts.montserrat.bold, color: colors.text.primary }}>
|
|
54
|
+
{data.name}
|
|
55
|
+
</Text>
|
|
56
|
+
<View
|
|
57
|
+
style={{
|
|
58
|
+
backgroundColor: statusColor + "20",
|
|
59
|
+
paddingHorizontal: 10,
|
|
60
|
+
paddingVertical: 4,
|
|
61
|
+
borderRadius: 20,
|
|
62
|
+
}}
|
|
63
|
+
>
|
|
64
|
+
<Text style={{ fontSize: textSize.sm, fontFamily: Fonts.montserrat.regular, color: statusColor }}>
|
|
65
|
+
{statusLabel}
|
|
66
|
+
</Text>
|
|
67
|
+
</View>
|
|
68
|
+
</View>
|
|
69
|
+
|
|
70
|
+
{addRow && (
|
|
71
|
+
<View style={{ flexDirection: rowDir, justifyContent: "space-between", alignItems: "center" }}>
|
|
72
|
+
<Text style={{ fontSize: textSize.xs, fontFamily: Fonts.montserrat.regular, color: colors.text.secondary }}>
|
|
73
|
+
{data.phone} · {vehicleLabel}
|
|
74
|
+
</Text>
|
|
75
|
+
{showCountdown ? (
|
|
76
|
+
<CircularCountdown deadline={deadline} onExpire={() => onExpire?.(data.id)} />
|
|
77
|
+
) : (
|
|
78
|
+
<View style={{ flexDirection: rowDir, alignItems: "center", gap: 4 }}>
|
|
79
|
+
<View style={[isRTL && { transform: [{ scaleX: -1 }] }]}>
|
|
80
|
+
<Clock width={13} height={13} color={colors.text.placeholder} />
|
|
81
|
+
</View>
|
|
82
|
+
<Text style={{ fontSize: textSize.xs, fontFamily: Fonts.montserrat.regular, color: colors.text.placeholder }}>
|
|
83
|
+
{agoText}
|
|
84
|
+
</Text>
|
|
85
|
+
</View>
|
|
86
|
+
)}
|
|
87
|
+
</View>
|
|
88
|
+
)}
|
|
89
|
+
</View>
|
|
90
|
+
|
|
91
|
+
<CardRow icon={Destination} label={labels.pickUp} value={locationName} />
|
|
92
|
+
<CardRow icon={Flag} label={labels.destination} value={destinationName} />
|
|
93
|
+
<CardRow icon={Warning} label={labels.carState} value={carStateText} />
|
|
94
|
+
<View style={{ borderWidth: 0.5, borderColor: colors.semantic.border }} />
|
|
95
|
+
<View
|
|
96
|
+
style={{
|
|
97
|
+
flexDirection: isRTL ? "row" : "row-reverse",
|
|
98
|
+
justifyContent: "space-between",
|
|
99
|
+
gap: 10,
|
|
100
|
+
}}
|
|
101
|
+
>
|
|
102
|
+
<Text
|
|
103
|
+
style={{
|
|
104
|
+
color: colors.text.secondary,
|
|
105
|
+
fontSize: textSize.sm,
|
|
106
|
+
fontFamily: Fonts.montserrat.regular,
|
|
107
|
+
}}
|
|
108
|
+
>
|
|
109
|
+
{labels.total}
|
|
110
|
+
</Text>
|
|
111
|
+
<Text
|
|
112
|
+
style={[
|
|
113
|
+
{
|
|
114
|
+
color: colors.text.primary,
|
|
115
|
+
fontSize: textSize.md,
|
|
116
|
+
fontFamily: Fonts.montserrat.semiBold,
|
|
117
|
+
},
|
|
118
|
+
]}
|
|
119
|
+
>
|
|
120
|
+
{`${formatPrice(data.price)} ${labels.currency}`}
|
|
121
|
+
</Text>
|
|
122
|
+
</View>
|
|
123
|
+
</View>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function CardRow({ icon: Icon, label, value }: { icon: React.ComponentType<SvgProps>; label: string; value: string }) {
|
|
128
|
+
const { isRTL } = useLanguage();
|
|
129
|
+
const { colors } = useAppTheme();
|
|
130
|
+
return (
|
|
131
|
+
<View style={{ flexDirection: isRTL ? "row" : "row-reverse", alignItems: "center", gap: 10 }}>
|
|
132
|
+
<View style={{ flexShrink: 0 }}>
|
|
133
|
+
<Icon color={colors.primary} width={20} height={20} />
|
|
134
|
+
</View>
|
|
135
|
+
<View style={{ flex: 1 }}>
|
|
136
|
+
<Text
|
|
137
|
+
style={{
|
|
138
|
+
fontSize: textSize.sm,
|
|
139
|
+
fontFamily: Fonts.montserrat.semiBold,
|
|
140
|
+
color: colors.text.secondary,
|
|
141
|
+
textAlign: isRTL ? "left" : "right",
|
|
142
|
+
}}
|
|
143
|
+
>
|
|
144
|
+
{label}
|
|
145
|
+
</Text>
|
|
146
|
+
<Text
|
|
147
|
+
numberOfLines={2}
|
|
148
|
+
style={{
|
|
149
|
+
fontSize: textSize.sm,
|
|
150
|
+
fontFamily: Fonts.montserrat.regular,
|
|
151
|
+
color: colors.text.primary,
|
|
152
|
+
textAlign: isRTL ? "left" : "right",
|
|
153
|
+
}}
|
|
154
|
+
>
|
|
155
|
+
{value}
|
|
156
|
+
</Text>
|
|
157
|
+
</View>
|
|
158
|
+
</View>
|
|
159
|
+
);
|
|
160
|
+
}
|
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 { RequestCardData, RequestCardLabels } from "./types/request";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type RequestCardData = {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string; // client name (provider app) or provider name (client app)
|
|
4
|
+
phone: string;
|
|
5
|
+
time: string; // ISO string, used for the countdown deadline
|
|
6
|
+
price: number;
|
|
7
|
+
location: [number, number]; // [lat, lng]
|
|
8
|
+
destination: [number, number]; // [lat, lng]
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type RequestCardLabels = {
|
|
12
|
+
pickUp: string;
|
|
13
|
+
destination: string;
|
|
14
|
+
carState: string;
|
|
15
|
+
total: string;
|
|
16
|
+
currency: string; // t("request.price.unit")
|
|
17
|
+
};
|