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 #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 df6a085
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 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 All @@ -67,6 +73,8 @@ export function getInitialState(
return res;
}



export default function (scenes:{string: any}) {
// find "root" component and get state from it
const rootRoute = Object.keys(scenes).find((route) =>
Expand Down

0 comments on commit df6a085

Please sign in to comment.