Skip to content

Commit

Permalink
fix(react): hardware back button works in dev mode (#26614)
Browse files Browse the repository at this point in the history
resolves #26599
  • Loading branch information
liamdebeasi authored Jan 19, 2023
1 parent dd7cd8c commit abcfe9f
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions packages/react/src/routing/NavManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ interface NavManagerProps {
}

export class NavManager extends React.PureComponent<NavManagerProps, NavContextState> {
_isMounted = false;

ionRouterContextValue: IonRouterContextState = {
push: (
pathname: string,
Expand Down Expand Up @@ -72,30 +70,25 @@ export class NavManager extends React.PureComponent<NavManagerProps, NavContextS
changeTab: this.props.onChangeTab,
resetTab: this.props.onResetTab,
};
}

componentDidMount() {
if (typeof document !== 'undefined') {
this.handleHardwareBackButton = this.handleHardwareBackButton.bind(this);
document.addEventListener('ionBackButton', this.handleHardwareBackButton);
}
}

componentDidMount() {
this._isMounted = true;
}

componentWillUnmount() {
if (typeof document !== 'undefined') {
document.removeEventListener('ionBackButton', this.handleHardwareBackButton);
this._isMounted = false;
}
}

handleHardwareBackButton(e: any) {
e.detail.register(0, (processNextHandler: () => void) => {
if (this._isMounted) {
this.nativeGoBack();
processNextHandler();
}
this.nativeGoBack();
processNextHandler();
});
}

Expand Down

0 comments on commit abcfe9f

Please sign in to comment.