-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
107 lines (100 loc) · 2.53 KB
/
App.tsx
File metadata and controls
107 lines (100 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import {
View,
StyleSheet,
StatusBar,
PermissionsAndroid,
Platform,
} from 'react-native';
import { useEffect, useRef, useState } from 'react';
import {
MapboxTurnByTurnNavigationView,
type LocationData,
} from 'react-native-mapbox-turn-by-turn-navigation';
import type {
Coordinate,
RouteProgress,
WaypointEvent,
} from '../../lib/typescript/src';
export default function App() {
const isMountedRef = useRef<boolean>(true);
const [ready, setReady] = useState(false);
const checkPermissions = async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
);
if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
console.warn('Location permission not granted');
return;
}
if (isMountedRef.current) setReady(true);
} catch (error) {
console.error('Error checking permissions:', error);
}
};
useEffect(() => {
isMountedRef.current = true;
if (Platform.OS === 'android') {
checkPermissions();
} else {
setReady(true); // Assume permissions are granted on iOS
}
return () => {
isMountedRef.current = false;
};
}, []);
if (!ready) {
return <View style={styles.container} />;
}
return (
<>
<StatusBar barStyle="dark-content" />
<View style={styles.container}>
<MapboxTurnByTurnNavigationView
style={styles.mapboxView}
origin={{
longitude: 5.082325,
latitude: 51.558588,
}}
destination={{
longitude: 5.058566,
latitude: 51.560985,
}}
onLocationChange={{
f: (event: LocationData) => {
console.log('Location changed:', event);
},
}}
onCancel={{
f: () => {
console.log('Navigation cancelled');
},
}}
onArrival={{
f: (coordinates: Coordinate) => {
console.log('Arrived at destination:', coordinates);
},
}}
onWaypointArrival={{
f: (event: WaypointEvent) => {
console.log('Arrived at waypoint:', event);
},
}}
onRouteProgressChange={{
f: (event: RouteProgress) => {
console.log('Route progress changed:', event);
},
}}
/>
</View>
</>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
mapboxView: {
flex: 1,
},
});