Skip to content

Commit

Permalink
fix(navigationState): avoid undefined key for root scenes
Browse files Browse the repository at this point in the history
This is one of the issues I've been investigating within my app.
Apparently aksonov#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"…}
```
  • Loading branch information
blackxored committed Jul 18, 2016
1 parent 822e83f commit d5bd9d6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/State.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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),
};
Expand Down

0 comments on commit d5bd9d6

Please sign in to comment.