@towsila/expo-ui-library 1.4.0 → 1.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 +5 -9
- package/src/hooks/useArrivalDetection.tsx +45 -0
- package/src/index.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@towsila/expo-ui-library",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -14,12 +14,13 @@
|
|
|
14
14
|
"peerDependencies": {
|
|
15
15
|
"@react-native-async-storage/async-storage": "*",
|
|
16
16
|
"expo": "*",
|
|
17
|
+
"expo-device": "*",
|
|
18
|
+
"expo-haptics": "^57.0.1",
|
|
17
19
|
"expo-linear-gradient": "*",
|
|
18
20
|
"expo-location": "*",
|
|
21
|
+
"expo-notifications": "*",
|
|
19
22
|
"expo-secure-store": "*",
|
|
20
23
|
"expo-splash-screen": "*",
|
|
21
|
-
"expo-notifications": "*",
|
|
22
|
-
"expo-device": "*",
|
|
23
24
|
"react": "*",
|
|
24
25
|
"react-native": "*",
|
|
25
26
|
"react-native-keyboard-aware-scroll-view": "*",
|
|
@@ -50,11 +51,6 @@
|
|
|
50
51
|
},
|
|
51
52
|
"dependencies": {
|
|
52
53
|
"@expo/vector-icons": "^15.1.1",
|
|
53
|
-
"@towsila/icons": "^1.0.3"
|
|
54
|
-
"expo-device": "^57.0.1",
|
|
55
|
-
"expo-linear-gradient": "*",
|
|
56
|
-
"expo-notifications": "^57.0.7",
|
|
57
|
-
"expo-secure-store": "*",
|
|
58
|
-
"react-native-svg": "*"
|
|
54
|
+
"@towsila/icons": "^1.0.3"
|
|
59
55
|
}
|
|
60
56
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/hooks/useArrivalDetection.ts
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import * as Haptics from "expo-haptics";
|
|
4
|
+
|
|
5
|
+
function getDistanceMeters(a: [number, number], b: [number, number]) {
|
|
6
|
+
const R = 6371000;
|
|
7
|
+
const toRad = (deg: number) => (deg * Math.PI) / 180;
|
|
8
|
+
const dLat = toRad(b[1] - a[1]);
|
|
9
|
+
const dLon = toRad(b[0] - a[0]);
|
|
10
|
+
const lat1 = toRad(a[1]);
|
|
11
|
+
const lat2 = toRad(b[1]);
|
|
12
|
+
const h =
|
|
13
|
+
Math.sin(dLat / 2) ** 2 +
|
|
14
|
+
Math.cos(lat1) * Math.cos(lat2) * Math.sin(dLon / 2) ** 2;
|
|
15
|
+
const c = 2 * Math.atan2(Math.sqrt(h), Math.sqrt(1 - h));
|
|
16
|
+
return R * c;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function useArrivalDetection(
|
|
20
|
+
currentCoords: [number, number] | null,
|
|
21
|
+
targetCoords: [number, number] | null,
|
|
22
|
+
thresholdMeters: number = 30
|
|
23
|
+
) {
|
|
24
|
+
const [hasArrived, setHasArrived] = useState(false);
|
|
25
|
+
const firedRef = useRef(false);
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (!currentCoords || !targetCoords) return;
|
|
29
|
+
|
|
30
|
+
const distance = getDistanceMeters(currentCoords, targetCoords);
|
|
31
|
+
|
|
32
|
+
if (distance <= thresholdMeters && !firedRef.current) {
|
|
33
|
+
firedRef.current = true;
|
|
34
|
+
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
|
|
35
|
+
setHasArrived(true);
|
|
36
|
+
}
|
|
37
|
+
}, [currentCoords, targetCoords, thresholdMeters]);
|
|
38
|
+
|
|
39
|
+
const reset = () => {
|
|
40
|
+
firedRef.current = false;
|
|
41
|
+
setHasArrived(false);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return { hasArrived, reset };
|
|
45
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -62,4 +62,5 @@ export {default as AccountStatusScreen} from "./components/screens/AccountStatus
|
|
|
62
62
|
export {sendEmail} from "./service/sendEmail";
|
|
63
63
|
export {useToast} from "./hooks/useToast";
|
|
64
64
|
export {default as RatingStars} from "./components/ui/rating";
|
|
65
|
-
export { getFcmToken } from "./hooks/useFcmToken";
|
|
65
|
+
export { getFcmToken } from "./hooks/useFcmToken";
|
|
66
|
+
export {useArrivalDetection} from "./hooks/useArrivalDetection";
|