Skip to content

Commit

Permalink
Fixes #2147, onExit handler (#2154)
Browse files Browse the repository at this point in the history
  • Loading branch information
aksonov authored Aug 1, 2017
1 parent 84a807d commit a124cc0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
5 changes: 4 additions & 1 deletion Example/Example.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ const Example = () => {
</Scene>
</Scene>
<Scene key="login">
<Scene key="loginModal" component={Login} title="Login" leftTitle="Cancel" onLeft={Actions.pop}/>
<Scene key="loginModal" component={Login} title="Login"
onEnter={()=>console.log('onEnter')}
onExit={()=>console.log('onExit')}
leftTitle="Cancel" onLeft={Actions.pop}/>
<Scene
key="loginModal2"
component={Login2}
Expand Down
22 changes: 11 additions & 11 deletions src/navigationStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,30 +388,28 @@ class NavigationStore {
return;
}
const state = getActiveState(newState);
const prevScene = this.prevScene;
const currentScene = this.currentScene;
const prevScene = this.prevScene;
this._state = newState;
if (prevScene !== this.prevScene) {
this.dispatch({ type: ActionConst.BLUR, routeName: this.prevScene });
this.currentScene = state.routeName;
this.currentParams = state.params;

if (currentScene !== this.currentScene) {
this.dispatch({ type: ActionConst.BLUR, routeName: prevScene });

// call onExit handler
const handler = this[this.prevScene + OnExit];
if (handler) {
const exitHandler = this[prevScene + OnExit];
if (exitHandler) {
try {
const res = handler();
const res = exitHandler();
if (res instanceof Promise) {
res.then(defaultSuccess, defaultFailure);
}
} catch (e) {
console.error('Error during onExit handler:', e);
}
}
}
this.prevScene = this.currentScene;
this.currentScene = state.routeName;
this.currentParams = state.params;

if (currentScene !== this.currentScene) {
this.dispatch({ type: ActionConst.FOCUS, routeName: this.currentScene, params: this.currentParams });
if (this.states[this.currentScene]) {
const handler = this[this.currentScene + OnEnter];
Expand All @@ -433,6 +431,8 @@ class NavigationStore {
}
}
}

this.prevScene = this.currentScene;
}
};

Expand Down

0 comments on commit a124cc0

Please sign in to comment.