11import getChildEventSubscriber from './getChildEventSubscriber' ;
22import getChildRouter from './getChildRouter' ;
33import getNavigationActionCreators from './routers/getNavigationActionCreators' ;
4+ import getChildrenNavigationCache from './getChildrenNavigationCache' ;
45
56const createParamGetter = route => ( paramName , defaultValue ) => {
67 const params = route . params ;
@@ -13,9 +14,7 @@ const createParamGetter = route => (paramName, defaultValue) => {
1314} ;
1415
1516function getChildNavigation ( navigation , childKey , getCurrentParentNavigation ) {
16- const children =
17- navigation . _childrenNavigation || ( navigation . _childrenNavigation = { } ) ;
18-
17+ const children = getChildrenNavigationCache ( navigation ) ;
1918 const childRoute = navigation . state . routes . find ( r => r . key === childKey ) ;
2019
2120 if ( ! childRoute ) {
@@ -66,47 +65,48 @@ function getChildNavigation(navigation, childKey, getCurrentParentNavigation) {
6665 getParam : createParamGetter ( childRoute ) ,
6766 } ;
6867 return children [ childKey ] ;
69- }
70-
71- const childSubscriber = getChildEventSubscriber (
72- navigation . addListener ,
73- childKey
74- ) ;
75-
76- children [ childKey ] = {
77- ...actionHelpers ,
68+ } else {
69+ const childSubscriber = getChildEventSubscriber (
70+ navigation . addListener ,
71+ childKey
72+ ) ;
7873
79- state : childRoute ,
80- router : childRouter ,
81- actions : actionCreators ,
82- getParam : createParamGetter ( childRoute ) ,
74+ children [ childKey ] = {
75+ ...actionHelpers ,
8376
84- getChildNavigation : grandChildKey =>
85- getChildNavigation ( children [ childKey ] , grandChildKey , ( ) => {
86- const nav = getCurrentParentNavigation ( ) ;
87- return nav && nav . getChildNavigation ( childKey ) ;
88- } ) ,
77+ state : childRoute ,
78+ router : childRouter ,
79+ actions : actionCreators ,
80+ getParam : createParamGetter ( childRoute ) ,
8981
90- isFocused : ( ) => {
91- const currentNavigation = getCurrentParentNavigation ( ) ;
92- if ( ! currentNavigation ) {
82+ getChildNavigation : grandChildKey =>
83+ getChildNavigation ( children [ childKey ] , grandChildKey , ( ) => {
84+ const nav = getCurrentParentNavigation ( ) ;
85+ return nav && nav . getChildNavigation ( childKey ) ;
86+ } ) ,
87+
88+ isFocused : ( ) => {
89+ const currentNavigation = getCurrentParentNavigation ( ) ;
90+ if ( ! currentNavigation ) {
91+ return false ;
92+ }
93+ const { routes, index } = currentNavigation . state ;
94+ if ( ! currentNavigation . isFocused ( ) ) {
95+ return false ;
96+ }
97+ if ( routes [ index ] . key === childKey ) {
98+ return true ;
99+ }
93100 return false ;
94- }
95- const { routes, index } = currentNavigation . state ;
96- if ( ! currentNavigation . isFocused ( ) ) {
97- return false ;
98- }
99- if ( routes [ index ] . key === childKey ) {
100- return true ;
101- }
102- return false ;
103- } ,
104- dispatch : navigation . dispatch ,
105- getScreenProps : navigation . getScreenProps ,
106- dangerouslyGetParent : getCurrentParentNavigation ,
107- addListener : childSubscriber . addListener ,
108- } ;
109- return children [ childKey ] ;
101+ } ,
102+ dispatch : navigation . dispatch ,
103+ getScreenProps : navigation . getScreenProps ,
104+ dangerouslyGetParent : getCurrentParentNavigation ,
105+ addListener : childSubscriber . addListener ,
106+ emit : childSubscriber . emit ,
107+ } ;
108+ return children [ childKey ] ;
109+ }
110110}
111111
112112export default getChildNavigation ;
0 commit comments