MOBILE-3320 android: Fix back button with leave guards
This commit is contained in:
		
							parent
							
								
									32810c54f0
								
							
						
					
					
						commit
						7cc8fa0b9e
					
				| @ -224,11 +224,17 @@ export class AppComponent implements OnInit, AfterViewInit { | ||||
|         document.addEventListener('ionBackButton', (event: BackButtonEvent) => { | ||||
|             // This callback should have the lowest priority in the app.
 | ||||
|             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.
 | ||||
|                 // 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.
 | ||||
|                 const initialPath = CoreNavigator.getCurrentPath(); | ||||
| 
 | ||||
|                 // The path seems to change immediately (0 ms timeout), but use 50ms just in case.
 | ||||
|                 await CoreUtils.wait(50); | ||||
| 
 | ||||
| @ -238,8 +244,7 @@ export class AppComponent implements OnInit, AfterViewInit { | ||||
|                 } | ||||
| 
 | ||||
|                 // Quit the app.
 | ||||
|                 const nav = <any> window.navigator; // eslint-disable-line @typescript-eslint/no-explicit-any
 | ||||
|                 nav.app?.exitApp(); | ||||
|                 CoreApp.closeApp(); | ||||
|             }); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
| @ -661,9 +661,7 @@ export class CoreLoginHelperProvider { | ||||
| 
 | ||||
|         // Always open it in browser because the user might have the session stored in there.
 | ||||
|         CoreUtils.openInBrowser(loginUrl); | ||||
| 
 | ||||
|         const nav = <any> window.navigator; // eslint-disable-line @typescript-eslint/no-explicit-any
 | ||||
|         nav.app?.exitApp(); | ||||
|         CoreApp.closeApp(); | ||||
| 
 | ||||
|         return true; | ||||
|     } | ||||
| @ -695,9 +693,7 @@ export class CoreLoginHelperProvider { | ||||
|             }); | ||||
|         } else { | ||||
|             CoreUtils.openInBrowser(loginUrl); | ||||
| 
 | ||||
|             const nav = <any> window.navigator; // eslint-disable-line @typescript-eslint/no-explicit-any
 | ||||
|             nav.app?.exitApp(); | ||||
|             CoreApp.closeApp(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -226,16 +226,10 @@ export class CoreMainMenuPage implements OnInit, OnDestroy { | ||||
|         // Use a priority lower than 0 (navigation).
 | ||||
|         event.detail.register(-10, async (processNextHandler: () => void) => { | ||||
|             // 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.
 | ||||
|             // 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.
 | ||||
|             await CoreUtils.wait(50); | ||||
| 
 | ||||
|             if (CoreNavigator.getCurrentPath() != initialPath) { | ||||
|                 // Ionic has navigated back, nothing else to do.
 | ||||
|                 return; | ||||
|             // Check if user is already at the root of a tab.
 | ||||
|             const mainMenuRootRoute = CoreNavigator.getCurrentRoute({ routeData: { isMainMenuRoot: true } }); | ||||
|             if (!mainMenuRootRoute) { | ||||
|                 return; // Not at root level, let Ionic handle the navigation.
 | ||||
|             } | ||||
| 
 | ||||
|             // 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], | ||||
|             useFactory: (injector: Injector) => buildTabMainRoutes(injector, { | ||||
|                 component: CoreMainMenuMorePage, | ||||
|                 data: { | ||||
|                     isMainMenuRoot: true, | ||||
|                 }, | ||||
|             }), | ||||
|         }, | ||||
|     ], | ||||
|  | ||||
| @ -562,6 +562,14 @@ export class CoreAppProvider { | ||||
|         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. | ||||
|      */ | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user