Fix nav state persistence

Summary:
We were saving the old state, so it would always be one screen away when reloading before.
Now it works the same way as android. Ideally we would factor out all this shared code...

Reviewed By: ericvicenti

Differential Revision: D4537509

fbshipit-source-id: 28ea8fd579521bd45829013364e884678af81c30
This commit is contained in:
Spencer Ahrens 2017-02-09 14:14:56 -08:00 committed by Facebook Github Bot
parent a023d0d057
commit 7ac1cc744c
1 changed files with 5 additions and 3 deletions

View File

@ -27,9 +27,9 @@ const AsyncStorage = require('AsyncStorage');
const Linking = require('Linking');
const React = require('react');
const ReactNative = require('react-native');
const UIExplorerList = require('./UIExplorerList.ios');
const UIExplorerExampleContainer = require('./UIExplorerExampleContainer');
const UIExplorerExampleList = require('./UIExplorerExampleList');
const UIExplorerList = require('./UIExplorerList.ios');
const UIExplorerNavigationReducer = require('./UIExplorerNavigationReducer');
const UIExplorerStateTitleMap = require('./UIExplorerStateTitleMap');
const URIActionMap = require('./URIActionMap');
@ -115,8 +115,10 @@ class UIExplorerApp extends React.Component {
}
const newState = UIExplorerNavigationReducer(this.state, action);
if (this.state !== newState) {
this.setState(newState);
AsyncStorage.setItem(APP_STATE_KEY, JSON.stringify(this.state));
this.setState(
newState,
() => AsyncStorage.setItem(APP_STATE_KEY, JSON.stringify(this.state))
);
}
}