Handle old navigation state safely.

Reviewed By: mkonicek

Differential Revision: D3359593

fbshipit-source-id: ca6dbcf14a31491bc6a3730243f358f21971e9f3
This commit is contained in:
Hedger Wang 2016-05-27 15:30:59 -07:00 committed by Facebook Github Bot 4
parent 3ba232f8fb
commit 708530a905

View File

@ -60,6 +60,8 @@ type State = UIExplorerNavigationState & {
externalExample?: string,
};
const APP_STATE_KEY = 'UIExplorerAppState.v1';
class UIExplorerApp extends React.Component {
_renderOverlay: Function;
_renderScene: Function;
@ -81,7 +83,7 @@ class UIExplorerApp extends React.Component {
componentDidMount() {
Linking.getInitialURL().then((url) => {
AsyncStorage.getItem('UIExplorerAppState', (err, storedString) => {
AsyncStorage.getItem(APP_STATE_KEY, (err, storedString) => {
const exampleAction = URIActionMap(this.props.exampleFromAppetizeParams);
const urlAction = URIActionMap(url);
const launchAction = exampleAction || urlAction;
@ -111,7 +113,7 @@ class UIExplorerApp extends React.Component {
const newState = UIExplorerNavigationReducer(this.state, action);
if (this.state !== newState) {
this.setState(newState);
AsyncStorage.setItem('UIExplorerAppState', JSON.stringify(this.state));
AsyncStorage.setItem(APP_STATE_KEY, JSON.stringify(this.state));
}
}