@@ -2,6 +2,7 @@ import * as React from 'react';
2
2
import * as CommonActions from './CommonActions' ;
3
3
import EnsureSingleNavigator from './EnsureSingleNavigator' ;
4
4
import NavigationBuilderContext from './NavigationBuilderContext' ;
5
+ import ResetRootContext from './ResetRootContext' ;
5
6
import useFocusedListeners from './useFocusedListeners' ;
6
7
import useDevTools from './useDevTools' ;
7
8
@@ -86,6 +87,23 @@ const Container = React.forwardRef(function NavigationContainer(
86
87
getPartialState ( initialState )
87
88
) ;
88
89
90
+ const navigationStateRef = React . useRef < State > ( ) ;
91
+ const transactionStateRef = React . useRef < State | null > ( null ) ;
92
+ const isTransactionActiveRef = React . useRef < boolean > ( false ) ;
93
+ const isFirstMountRef = React . useRef < boolean > ( true ) ;
94
+ const skipTrackingRef = React . useRef < boolean > ( false ) ;
95
+
96
+ const reset = React . useCallback ( ( state : NavigationState ) => {
97
+ skipTrackingRef . current = true ;
98
+ setNavigationState ( state ) ;
99
+ } , [ ] ) ;
100
+
101
+ const { trackState, trackAction } = useDevTools ( {
102
+ name : '@react-navigation' ,
103
+ reset,
104
+ state,
105
+ } ) ;
106
+
89
107
const { listeners, addListener : addFocusedListener } = useFocusedListeners ( ) ;
90
108
91
109
const dispatch = (
@@ -106,6 +124,14 @@ const Container = React.forwardRef(function NavigationContainer(
106
124
}
107
125
} ;
108
126
127
+ const resetRoot = React . useCallback (
128
+ ( state : PartialState < NavigationState > | NavigationState ) => {
129
+ trackAction ( '@@RESET_ROOT' ) ;
130
+ setNavigationState ( state ) ;
131
+ } ,
132
+ [ trackAction ]
133
+ ) ;
134
+
109
135
React . useImperativeHandle ( ref , ( ) => ( {
110
136
...( Object . keys ( CommonActions ) as Array < keyof typeof CommonActions > ) . reduce <
111
137
any
@@ -120,31 +146,11 @@ const Container = React.forwardRef(function NavigationContainer(
120
146
) ;
121
147
return acc ;
122
148
} , { } ) ,
123
- resetRoot : ( state : PartialState < NavigationState > | NavigationState ) => {
124
- trackAction ( '@@RESET_ROOT' ) ;
125
- setNavigationState ( state ) ;
126
- } ,
149
+ resetRoot,
127
150
dispatch,
128
151
canGoBack,
129
152
} ) ) ;
130
153
131
- const navigationStateRef = React . useRef < State > ( ) ;
132
- const transactionStateRef = React . useRef < State | null > ( null ) ;
133
- const isTransactionActiveRef = React . useRef < boolean > ( false ) ;
134
- const isFirstMountRef = React . useRef < boolean > ( true ) ;
135
- const skipTrackingRef = React . useRef < boolean > ( false ) ;
136
-
137
- const reset = React . useCallback ( ( state : NavigationState ) => {
138
- skipTrackingRef . current = true ;
139
- setNavigationState ( state ) ;
140
- } , [ ] ) ;
141
-
142
- const { trackState, trackAction } = useDevTools ( {
143
- name : '@react-navigation' ,
144
- reset,
145
- state,
146
- } ) ;
147
-
148
154
const builderContext = React . useMemo (
149
155
( ) => ( {
150
156
addFocusedListener,
@@ -220,7 +226,9 @@ const Container = React.forwardRef(function NavigationContainer(
220
226
return (
221
227
< NavigationBuilderContext . Provider value = { builderContext } >
222
228
< NavigationStateContext . Provider value = { context } >
223
- < EnsureSingleNavigator > { children } </ EnsureSingleNavigator >
229
+ < ResetRootContext . Provider value = { resetRoot } >
230
+ < EnsureSingleNavigator > { children } </ EnsureSingleNavigator >
231
+ </ ResetRootContext . Provider >
224
232
</ NavigationStateContext . Provider >
225
233
</ NavigationBuilderContext . Provider >
226
234
) ;
0 commit comments