fix(react): hardware back button works in dev mode (#26614)

resolves #26599
This commit is contained in:
Liam DeBeasi
2023-01-19 10:49:47 -05:00
committed by GitHub
parent dd7cd8c0bf
commit abcfe9fe86

View File

@ -37,8 +37,6 @@ interface NavManagerProps {
} }
export class NavManager extends React.PureComponent<NavManagerProps, NavContextState> { export class NavManager extends React.PureComponent<NavManagerProps, NavContextState> {
_isMounted = false;
ionRouterContextValue: IonRouterContextState = { ionRouterContextValue: IonRouterContextState = {
push: ( push: (
pathname: string, pathname: string,
@ -72,30 +70,25 @@ export class NavManager extends React.PureComponent<NavManagerProps, NavContextS
changeTab: this.props.onChangeTab, changeTab: this.props.onChangeTab,
resetTab: this.props.onResetTab, resetTab: this.props.onResetTab,
}; };
}
componentDidMount() {
if (typeof document !== 'undefined') { if (typeof document !== 'undefined') {
this.handleHardwareBackButton = this.handleHardwareBackButton.bind(this); this.handleHardwareBackButton = this.handleHardwareBackButton.bind(this);
document.addEventListener('ionBackButton', this.handleHardwareBackButton); document.addEventListener('ionBackButton', this.handleHardwareBackButton);
} }
} }
componentDidMount() {
this._isMounted = true;
}
componentWillUnmount() { componentWillUnmount() {
if (typeof document !== 'undefined') { if (typeof document !== 'undefined') {
document.removeEventListener('ionBackButton', this.handleHardwareBackButton); document.removeEventListener('ionBackButton', this.handleHardwareBackButton);
this._isMounted = false;
} }
} }
handleHardwareBackButton(e: any) { handleHardwareBackButton(e: any) {
e.detail.register(0, (processNextHandler: () => void) => { e.detail.register(0, (processNextHandler: () => void) => {
if (this._isMounted) { this.nativeGoBack();
this.nativeGoBack(); processNextHandler();
processNextHandler();
}
}); });
} }