File tree Expand file tree Collapse file tree 3 files changed +727
-18
lines changed
Expand file tree Collapse file tree 3 files changed +727
-18
lines changed Original file line number Diff line number Diff line change 133133 "peerDependencies" : {
134134 "@react-navigation/native" : " ^6.0.0" ,
135135 "@types/react" : " ^16.8.4 || ^17.0.0 || ^18.0.0" ,
136+ "expo-router" : " ^3.0.0" ,
136137 "react" : " ^16.8.4 || ^17.0.0 || ^18.0.0"
137138 },
138139 "peerDependenciesMeta" : {
141142 },
142143 "@types/react" : {
143144 "optional" : true
145+ },
146+ "expo-router" : {
147+ "optional" : true
144148 }
145149 },
146150 "devDependencies" : {
147151 "@anansi/browserslist-config" : " ^1.4.2" ,
148152 "@react-navigation/native" : " ^6.1.6" ,
149153 "@types/node" : " ^20.0.0" ,
150154 "@types/react" : " ^18.0.30" ,
155+ "expo-router" : " ^3.4.8" ,
151156 "react-native" : " ^0.73.0"
152157 }
153158}
Original file line number Diff line number Diff line change 1- import type { useNavigation , NavigationProp } from '@react-navigation/native' ;
21import {
32 type DependencyList ,
43 type EffectCallback ,
54 useEffect ,
65 useRef ,
76} from 'react' ;
87
9- const fakeNavigation = { addListener ( name : string ) { } } as any ;
10- let _useNavigation : typeof useNavigation = ( ) => fakeNavigation ;
11- import ( '@react-navigation/native' )
12- . then ( rn => {
13- _useNavigation = rn . useNavigation ;
8+ const fakeNavigation = {
9+ addListener ( name : string , cb : ( ) => void ) {
10+ return ( ) => { } ;
11+ } ,
12+ } ;
13+ let _useNavigation = ( ) => fakeNavigation ;
14+
15+ console . log ( '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>' ) ;
16+ // if they are using expo-router they are more likely wanting to use that implementation
17+ // as react-navigation can often appear in node_modules when not used
18+ import ( 'expo-router' )
19+ . then ( router => {
20+ _useNavigation = router . useNavigation ;
21+ console . log ( 'hi' , _useNavigation , router ) ;
1422 } )
15- . catch ( ( ) => { } ) ;
23+ . catch ( e => {
24+ console . log ( 'caught error' , e ) ;
25+ import ( '@react-navigation/native' )
26+ . then ( rn => {
27+ _useNavigation = rn . useNavigation ;
28+ } )
29+ . catch ( ( ) => { } ) ;
30+ } ) ;
1631
1732function useFocusEffect (
1833 effect : EffectCallback ,
1934 deps ?: DependencyList ,
2035 runOnMount = false ,
2136) {
22- let navigation : NavigationProp < ReactNavigation . RootParamList > ;
37+ let navigation : typeof fakeNavigation ;
2338 // if we aren't in react-navigation context, just ignore focus events
2439 try {
2540 navigation = _useNavigation ( ) ;
You can’t perform that action at this time.
0 commit comments