From 04f8fd47f37485f1efd4d2cf3da0be25109a594a Mon Sep 17 00:00:00 2001 From: Eric Vicenti Date: Tue, 3 Jul 2018 12:03:54 -0700 Subject: [PATCH] Avoid crash when calling isFocused on old route (#4634) --- .../react-navigation/src/getChildNavigation.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/react-navigation/src/getChildNavigation.js b/packages/react-navigation/src/getChildNavigation.js index 6f4afd9e..441c05cb 100644 --- a/packages/react-navigation/src/getChildNavigation.js +++ b/packages/react-navigation/src/getChildNavigation.js @@ -19,6 +19,10 @@ function getChildNavigation(navigation, childKey, getCurrentParentNavigation) { const childRoute = navigation.state.routes.find(r => r.key === childKey); + if (!childRoute) { + return null; + } + if (children[childKey] && children[childKey].state === childRoute) { return children[childKey]; } @@ -79,12 +83,16 @@ function getChildNavigation(navigation, childKey, getCurrentParentNavigation) { getParam: createParamGetter(childRoute), getChildNavigation: grandChildKey => - getChildNavigation(children[childKey], grandChildKey, () => - getCurrentParentNavigation().getChildNavigation(childKey) - ), + getChildNavigation(children[childKey], grandChildKey, () => { + const nav = getCurrentParentNavigation(); + return nav && nav.getChildNavigation(childKey); + }), isFocused: () => { const currentNavigation = getCurrentParentNavigation(); + if (!currentNavigation) { + return false; + } const { routes, index } = currentNavigation.state; if (!currentNavigation.isFocused()) { return false;