mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-03-06 22:39:41 +08:00
Backport child navigation cache fix
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import getChildEventSubscriber from './getChildEventSubscriber';
|
||||
import getChildRouter from './getChildRouter';
|
||||
import getNavigationActionCreators from './routers/getNavigationActionCreators';
|
||||
import getChildrenNavigationCache from './getChildrenNavigationCache';
|
||||
import invariant from './utils/invariant';
|
||||
|
||||
const createParamGetter = route => (paramName, defaultValue) => {
|
||||
@@ -14,8 +15,7 @@ const createParamGetter = route => (paramName, defaultValue) => {
|
||||
};
|
||||
|
||||
function getChildNavigation(navigation, childKey, getCurrentParentNavigation) {
|
||||
const children =
|
||||
navigation._childrenNavigation || (navigation._childrenNavigation = {});
|
||||
const children = getChildrenNavigationCache(navigation);
|
||||
|
||||
const childRoute = navigation.state.routes.find(r => r.key === childKey);
|
||||
|
||||
|
||||
16
src/getChildrenNavigationCache.js
Normal file
16
src/getChildrenNavigationCache.js
Normal file
@@ -0,0 +1,16 @@
|
||||
export default function getChildrenNavigationCache(navigation) {
|
||||
if (!navigation) {
|
||||
return {};
|
||||
}
|
||||
|
||||
let childrenNavigationCache =
|
||||
navigation._childrenNavigation || (navigation._childrenNavigation = {});
|
||||
let childKeys = navigation.state.routes.map(route => route.key);
|
||||
Object.keys(childrenNavigationCache).forEach(cacheKey => {
|
||||
if (!childKeys.includes(cacheKey)) {
|
||||
delete childrenNavigationCache[cacheKey];
|
||||
}
|
||||
});
|
||||
|
||||
return navigation._childrenNavigation;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import getNavigationActionCreators from './routers/getNavigationActionCreators';
|
||||
import getChildNavigation from './getChildNavigation';
|
||||
import getChildrenNavigationCache from './getChildrenNavigationCache';
|
||||
|
||||
export default function getNavigation(
|
||||
router,
|
||||
@@ -38,6 +39,7 @@ export default function getNavigation(
|
||||
};
|
||||
},
|
||||
dangerouslyGetParent: () => null,
|
||||
_childrenNavigation: getChildrenNavigationCache(getCurrentNavigation()),
|
||||
};
|
||||
|
||||
const actionCreators = {
|
||||
|
||||
Reference in New Issue
Block a user