File tree 3 files changed +802
-25
lines changed 3 files changed +802
-25
lines changed Original file line number Diff line number Diff line change 133
133
"peerDependencies" : {
134
134
"@react-navigation/native" : " ^6.0.0" ,
135
135
"@types/react" : " ^16.8.4 || ^17.0.0 || ^18.0.0 || ^19.0.0" ,
136
+ "expo-router" : " ^3.0.0" ,
136
137
"react" : " ^16.8.4 || ^17.0.0 || ^18.0.0 || ^19.0.0"
137
138
},
138
139
"peerDependenciesMeta" : {
141
142
},
142
143
"@types/react" : {
143
144
"optional" : true
145
+ },
146
+ "expo-router" : {
147
+ "optional" : true
144
148
}
145
149
},
146
150
"devDependencies" : {
147
151
"@anansi/browserslist-config" : " ^1.4.2" ,
148
152
"@react-navigation/native" : " ^6.1.6" ,
149
153
"@types/node" : " ^20.0.0" ,
150
154
"@types/react" : " ^18.0.30" ,
155
+ "expo-router" : " ^3.4.8" ,
151
156
"react-native" : " ^0.74.0"
152
157
}
153
158
}
Original file line number Diff line number Diff line change 1
- import type { useNavigation , NavigationProp } from '@react-navigation/native' ;
2
1
import {
3
2
type DependencyList ,
4
3
type EffectCallback ,
5
4
useEffect ,
6
5
useRef ,
7
6
} from 'react' ;
8
7
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 ) ;
14
22
} )
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
+ } ) ;
16
31
17
32
function useFocusEffect (
18
33
effect : EffectCallback ,
19
34
deps ?: DependencyList ,
20
35
runOnMount = false ,
21
36
) {
22
- let navigation : NavigationProp < ReactNavigation . RootParamList > ;
37
+ let navigation : typeof fakeNavigation ;
23
38
// if we aren't in react-navigation context, just ignore focus events
24
39
try {
25
40
navigation = _useNavigation ( ) ;
You can’t perform that action at this time.
0 commit comments