Skip to content

Commit

Permalink
Merge pull request #9 from summer88123/patch-2
Browse files Browse the repository at this point in the history
Fix: Android back button handler.
  • Loading branch information
shallot authored Feb 4, 2019
2 parents 3113391 + 9a7ef00 commit 9528b13
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/navibar.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ export class InnerNaviBar extends React.PureComponent {
left: null,
right: null,
};
this._didFocusSubscription = props.navigation.addListener('didFocus',
() => BackHandler.addEventListener('hardwareBackPress', this._clickBack));
}

componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', this._clickBack);
this._willBlurSubscription = this.props.navigation.addListener('willBlur',
() => BackHandler.removeEventListener('hardwareBackPress', this._clickBack));
Dimensions.addEventListener('change', this._onWindowChanged);
}

componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this._clickBack);
this._didFocusSubscription && this._didFocusSubscription.remove();
this._willBlurSubscription && this._willBlurSubscription.remove();
Dimensions.removeEventListener('change', this._onWindowChanged);
}

Expand Down

0 comments on commit 9528b13

Please sign in to comment.