@@ -6,12 +6,12 @@ import {
66 PartialState ,
77} from '@react-navigation/routers' ;
88import NavigationStateContext from './NavigationStateContext' ;
9- import NavigationContext from './NavigationContext' ;
10- import NavigationRouteContext from './NavigationRouteContext' ;
119import StaticContainer from './StaticContainer' ;
1210import EnsureSingleNavigator from './EnsureSingleNavigator' ;
13- import { NavigationProp , RouteConfig , EventMapBase } from './types' ;
1411import useOptionsGetters from './useOptionsGetters' ;
12+ import NavigationBuilderContext from './NavigationBuilderContext' ;
13+ import useFocusEffect from './useFocusEffect' ;
14+ import { NavigationProp , RouteConfig , EventMapBase } from './types' ;
1515
1616type Props <
1717 State extends NavigationState ,
@@ -45,21 +45,25 @@ export default function SceneView<
4545 options,
4646} : Props < State , ScreenOptions , EventMap > ) {
4747 const navigatorKeyRef = React . useRef < string | undefined > ( ) ;
48+ const { onOptionsChange } = React . useContext ( NavigationBuilderContext ) ;
4849 const getKey = React . useCallback ( ( ) => navigatorKeyRef . current , [ ] ) ;
49-
5050 const optionsRef = React . useRef < object | undefined > ( options ) ;
51-
52- React . useEffect ( ( ) => {
53- optionsRef . current = options ;
54- } , [ options ] ) ;
55-
5651 const getOptions = React . useCallback ( ( ) => optionsRef . current , [ ] ) ;
5752
58- const { addOptionsGetter } = useOptionsGetters ( {
53+ const { addOptionsGetter, hasAnyChildListener } = useOptionsGetters ( {
5954 key : route . key ,
6055 getOptions,
6156 } ) ;
6257
58+ const optionsChange = React . useCallback ( ( ) => {
59+ optionsRef . current = options ;
60+ if ( ! hasAnyChildListener ) {
61+ onOptionsChange ( options ) ;
62+ }
63+ } , [ onOptionsChange , options , hasAnyChildListener ] ) ;
64+
65+ useFocusEffect ( optionsChange ) ;
66+
6367 const setKey = React . useCallback ( ( key : string ) => {
6468 navigatorKeyRef . current = key ;
6569 } , [ ] ) ;
@@ -105,28 +109,24 @@ export default function SceneView<
105109 ) ;
106110
107111 return (
108- < NavigationContext . Provider value = { navigation } >
109- < NavigationRouteContext . Provider value = { route } >
110- < NavigationStateContext . Provider value = { context } >
111- < EnsureSingleNavigator >
112- < StaticContainer
113- name = { screen . name }
114- // @ts -ignore
115- render = { screen . component || screen . children }
116- navigation = { navigation }
117- route = { route }
118- >
119- { 'component' in screen && screen . component !== undefined ? (
120- // @ts -ignore
121- < screen . component navigation = { navigation } route = { route } />
122- ) : 'children' in screen && screen . children !== undefined ? (
123- // @ts -ignore
124- screen . children ( { navigation, route } )
125- ) : null }
126- </ StaticContainer >
127- </ EnsureSingleNavigator >
128- </ NavigationStateContext . Provider >
129- </ NavigationRouteContext . Provider >
130- </ NavigationContext . Provider >
112+ < NavigationStateContext . Provider value = { context } >
113+ < EnsureSingleNavigator >
114+ < StaticContainer
115+ name = { screen . name }
116+ // @ts -ignore
117+ render = { screen . component || screen . children }
118+ navigation = { navigation }
119+ route = { route }
120+ >
121+ { 'component' in screen && screen . component !== undefined ? (
122+ // @ts -ignore
123+ < screen . component navigation = { navigation } route = { route } />
124+ ) : 'children' in screen && screen . children !== undefined ? (
125+ // @ts -ignore
126+ screen . children ( { navigation, route } )
127+ ) : null }
128+ </ StaticContainer >
129+ </ EnsureSingleNavigator >
130+ </ NavigationStateContext . Provider >
131131 ) ;
132132}
0 commit comments