mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-10 00:27:41 +08:00
fix(react): hardware back button works in dev mode (#26614)
resolves #26599
This commit is contained in:
@ -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();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user