diff --git a/Examples/UIExplorer/UIExplorerList.ios.js b/Examples/UIExplorer/UIExplorerList.ios.js index 2e1c444f1..d2e04063b 100644 --- a/Examples/UIExplorer/UIExplorerList.ios.js +++ b/Examples/UIExplorer/UIExplorerList.ios.js @@ -121,23 +121,30 @@ class UIExplorerList extends React.Component { ); } - componentWillMount() { - this.props.navigator.navigationContext.addListener('didfocus', function(event) { - if (event.data.route.title === 'UIExplorer') { - Settings.set({visibleExample: null}); - } - }); - } - componentDidMount() { - var visibleExampleTitle = Settings.get('visibleExample'); - if (visibleExampleTitle) { - var predicate = (example) => example.title === visibleExampleTitle; - var foundExample = APIS.find(predicate) || COMPONENTS.find(predicate); - if (foundExample) { - setTimeout(() => this._openExample(foundExample), 100); + var wasUIExplorer = false; + var didOpenExample = false; + + this.props.navigator.navigationContext.addListener('didfocus', (event) => { + var isUIExplorer = event.data.route.title === 'UIExplorer'; + + if (!didOpenExample && isUIExplorer) { + didOpenExample = true; + + var visibleExampleTitle = Settings.get('visibleExample'); + if (visibleExampleTitle) { + var predicate = (example) => example.title === visibleExampleTitle; + var foundExample = APIS.find(predicate) || COMPONENTS.find(predicate); + if (foundExample) { + setTimeout(() => this._openExample(foundExample), 100); + } + } else if (!wasUIExplorer && isUIExplorer) { + Settings.set({visibleExample: null}); + } } - } + + wasUIExplorer = isUIExplorer; + }); } renderAdditionalView(renderRow: Function, renderTextInput: Function): React.Component { diff --git a/Examples/UIExplorer/UIExplorerList.js b/Examples/UIExplorer/UIExplorerList.js index c3fc0492a..cbb24a126 100644 --- a/Examples/UIExplorer/UIExplorerList.js +++ b/Examples/UIExplorer/UIExplorerList.js @@ -166,15 +166,6 @@ class UIExplorerList extends React.Component { componentDidMount() { this._search(this.state.searchText); - - var visibleExampleTitle = Settings.get('visibleExample'); - if (visibleExampleTitle) { - var predicate = (example) => example.title === visibleExampleTitle; - var foundExample = APIS.find(predicate) || COMPONENTS.find(predicate); - if (foundExample) { - setTimeout(() => this._openExample(foundExample), 100); - } - } } render() {