1+ import type { ComponentProps } from 'react' ;
2+
13const MapboxTurnByTurnNavigationConfig = require ( '../nitrogen/generated/shared/json/MapboxTurnByTurnNavigationConfig.json' ) ;
24import type {
35 MapboxTurnByTurnNavigationMethods ,
@@ -6,62 +8,17 @@ import type {
68
79export * from './MapboxTurnByTurnNavigation.nitro' ;
810
9- import { type ComponentProps , useEffect , useRef , useState } from 'react' ;
10- import {
11- PermissionsAndroid ,
12- Platform ,
13- type StyleProp ,
14- StyleSheet ,
15- View ,
16- type ViewStyle ,
17- } from 'react-native' ;
11+ import { StyleSheet , View } from 'react-native' ;
1812import { getHostComponent } from 'react-native-nitro-modules' ;
1913
2014export const NativeView = getHostComponent <
2115 MapboxTurnByTurnNavigationProps ,
2216 MapboxTurnByTurnNavigationMethods
2317> ( 'MapboxTurnByTurnNavigation' , ( ) => MapboxTurnByTurnNavigationConfig ) ;
2418
25- type NativeViewProps = ComponentProps < typeof NativeView > ;
26- interface MapboxTurnByTurnNavigationView extends NativeViewProps {
27- style ?: StyleProp < ViewStyle > ;
28- }
2919export const MapboxTurnByTurnNavigationView = (
30- props : MapboxTurnByTurnNavigationView
20+ props : ComponentProps < typeof NativeView >
3121) => {
32- const isMountedRef = useRef < boolean > ( true ) ;
33- const [ ready , setReady ] = useState ( false ) ;
34-
35- const checkPermissions = async ( ) => {
36- try {
37- const granted = await PermissionsAndroid . request (
38- PermissionsAndroid . PERMISSIONS . ACCESS_FINE_LOCATION
39- ) ;
40- if ( granted !== PermissionsAndroid . RESULTS . GRANTED ) {
41- console . warn ( 'Location permission not granted' ) ;
42- return ;
43- }
44- if ( isMountedRef . current ) setReady ( true ) ;
45- } catch ( error ) {
46- console . error ( 'Error checking permissions:' , error ) ;
47- }
48- } ;
49-
50- useEffect ( ( ) => {
51- isMountedRef . current = true ;
52- if ( Platform . OS === 'android' ) {
53- checkPermissions ( ) ;
54- } else {
55- setReady ( true ) ; // Assume permissions are granted on iOS
56- }
57- return ( ) => {
58- isMountedRef . current = false ;
59- } ;
60- } , [ ] ) ;
61-
62- if ( ! ready ) {
63- return < View style = { styles . container } /> ;
64- }
6522 return (
6623 < View style = { [ styles . container , props . style ] } >
6724 < NativeView { ...props } style = { styles . container } />
0 commit comments