MOBILE-3320 android: Fix back button with leave guards
parent
32810c54f0
commit
7cc8fa0b9e
|
@ -224,11 +224,17 @@ export class AppComponent implements OnInit, AfterViewInit {
|
||||||
document.addEventListener('ionBackButton', (event: BackButtonEvent) => {
|
document.addEventListener('ionBackButton', (event: BackButtonEvent) => {
|
||||||
// This callback should have the lowest priority in the app.
|
// This callback should have the lowest priority in the app.
|
||||||
event.detail.register(-100, async () => {
|
event.detail.register(-100, async () => {
|
||||||
|
const initialPath = CoreNavigator.getCurrentPath();
|
||||||
|
if (initialPath.startsWith('/main/')) {
|
||||||
|
// Main menu has its own callback to handle back. If this callback is called it means we should exit app.
|
||||||
|
CoreApp.closeApp();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// This callback can be called at the same time as Ionic's back navigation callback.
|
// This callback can be called at the same time as Ionic's back navigation callback.
|
||||||
// Check if the path changes due to the back navigation handler, to know if we're at root level.
|
// Check if the path changes due to the back navigation handler, to know if we're at root level.
|
||||||
// Ionic doc recommends IonRouterOutlet.canGoBack, but there's no easy way to get the current outlet from here.
|
// Ionic doc recommends IonRouterOutlet.canGoBack, but there's no easy way to get the current outlet from here.
|
||||||
const initialPath = CoreNavigator.getCurrentPath();
|
|
||||||
|
|
||||||
// The path seems to change immediately (0 ms timeout), but use 50ms just in case.
|
// The path seems to change immediately (0 ms timeout), but use 50ms just in case.
|
||||||
await CoreUtils.wait(50);
|
await CoreUtils.wait(50);
|
||||||
|
|
||||||
|
@ -238,8 +244,7 @@ export class AppComponent implements OnInit, AfterViewInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quit the app.
|
// Quit the app.
|
||||||
const nav = <any> window.navigator; // eslint-disable-line @typescript-eslint/no-explicit-any
|
CoreApp.closeApp();
|
||||||
nav.app?.exitApp();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -661,9 +661,7 @@ export class CoreLoginHelperProvider {
|
||||||
|
|
||||||
// Always open it in browser because the user might have the session stored in there.
|
// Always open it in browser because the user might have the session stored in there.
|
||||||
CoreUtils.openInBrowser(loginUrl);
|
CoreUtils.openInBrowser(loginUrl);
|
||||||
|
CoreApp.closeApp();
|
||||||
const nav = <any> window.navigator; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
||||||
nav.app?.exitApp();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -695,9 +693,7 @@ export class CoreLoginHelperProvider {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
CoreUtils.openInBrowser(loginUrl);
|
CoreUtils.openInBrowser(loginUrl);
|
||||||
|
CoreApp.closeApp();
|
||||||
const nav = <any> window.navigator; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
||||||
nav.app?.exitApp();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -226,16 +226,10 @@ export class CoreMainMenuPage implements OnInit, OnDestroy {
|
||||||
// Use a priority lower than 0 (navigation).
|
// Use a priority lower than 0 (navigation).
|
||||||
event.detail.register(-10, async (processNextHandler: () => void) => {
|
event.detail.register(-10, async (processNextHandler: () => void) => {
|
||||||
// This callback can be called at the same time as Ionic's back navigation callback.
|
// This callback can be called at the same time as Ionic's back navigation callback.
|
||||||
// Check if the path changes due to the back navigation handler, to know if we're at root level of the tab.
|
// Check if user is already at the root of a tab.
|
||||||
// Ionic doc recommends IonRouterOutlet.canGoBack, but there's no easy way to get the current outlet from here.
|
const mainMenuRootRoute = CoreNavigator.getCurrentRoute({ routeData: { isMainMenuRoot: true } });
|
||||||
const initialPath = CoreNavigator.getCurrentPath();
|
if (!mainMenuRootRoute) {
|
||||||
|
return; // Not at root level, let Ionic handle the navigation.
|
||||||
// The path seems to change immediately (0 ms timeout), but use 50ms just in case.
|
|
||||||
await CoreUtils.wait(50);
|
|
||||||
|
|
||||||
if (CoreNavigator.getCurrentPath() != initialPath) {
|
|
||||||
// Ionic has navigated back, nothing else to do.
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// No back navigation, already at root level. Check if we should change tab.
|
// No back navigation, already at root level. Check if we should change tab.
|
||||||
|
|
|
@ -30,6 +30,9 @@ import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.modu
|
||||||
deps: [Injector],
|
deps: [Injector],
|
||||||
useFactory: (injector: Injector) => buildTabMainRoutes(injector, {
|
useFactory: (injector: Injector) => buildTabMainRoutes(injector, {
|
||||||
component: CoreMainMenuMorePage,
|
component: CoreMainMenuMorePage,
|
||||||
|
data: {
|
||||||
|
isMainMenuRoot: true,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -562,6 +562,14 @@ export class CoreAppProvider {
|
||||||
return redirect;
|
return redirect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the app.
|
||||||
|
*/
|
||||||
|
closeApp(): void {
|
||||||
|
const nav = <any> window.navigator; // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||||
|
nav.app?.exitApp();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forget redirect data.
|
* Forget redirect data.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue