From d5bd9d6c34030b2835ba531d968771a6b2120355 Mon Sep 17 00:00:00 2001 From: Adrian Perez Date: Mon, 18 Jul 2016 21:59:27 +0200 Subject: [PATCH] fix(navigationState): avoid undefined key for root scenes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is one of the issues I've been investigating within my app. Apparently #911 broke scene key generation when the scene has no parent. Before: ```javascript Object {key: "undefined_undefined_0_home_", name: "home", sceneKey: "home_", parent: "home", type: "REACT_NATIVE_ROUTER_FLUX_PUSH"…} ``` After: ```javascript Object {key: "0_home_", name: "home", sceneKey: "home_", parent: "home", type: "REACT_NATIVE_ROUTER_FLUX_PUSH"…} ``` --- src/State.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/State.js b/src/State.js index 7c18c5c0f..7db3de930 100644 --- a/src/State.js +++ b/src/State.js @@ -30,6 +30,12 @@ function getStateFromScenes(route, scenes, props) { return result; } +function getSceneKey(parent, key, position, sceneKey) { + return [parent, key, position, sceneKey] + .filter(v => typeof(v) !== 'undefined' && v !== null) + .join('_'); +} + export function getInitialState( route: {string: any}, scenes: {string: any}, @@ -42,7 +48,7 @@ export function getInitialState( return { ...scenes.rootProps, ...route, - key: `${parent}_${key}_${position}_${route.sceneKey}`, + key: getSceneKey(parent, key, position, route.sceneKey), ...parentProps, ...getStateFromScenes(route, scenes, props), };