void NavigationPopCallback(MessageBus bus, NavigationPopInfo navigationPopInfo) { if (navigationPopInfo == null) { throw new ArgumentNullException(nameof(navigationPopInfo)); } if (!navigationPopInfo.Force && _isBusy) { return; } if (_app == null) { throw new FieldAccessException(@"Application property not set. Use Init() before navigation"); } if (_navigations.Count == 0) { throw new FieldAccessException(@"Navigation is null. Add NavigationPage first"); } Device.BeginInvokeOnMainThread(async() => { _isBusy = true; try { await Pop(navigationPopInfo); } catch (Exception) { // ignore } _isBusy = false; }); }
async Task Pop(NavigationPopInfo popInfo) { INavigation navigation; switch (popInfo.Mode) { case NavigationMode.Normal: if (_navigations.TryPeek(out navigation)) { await NormalPop(popInfo.WithAnimation, navigation); } break; case NavigationMode.Modal: if (_navigations.TryPop(out navigation) && navigation.ModalStack.Count > 0) { await ModalPop(popInfo.WithAnimation, navigation); } break; case NavigationMode.Root: if (_navigations.TryPeek(out navigation)) { var pagesToDispose = navigation.NavigationStack?.Count > 0 ? navigation.NavigationStack.Where(p => p != navigation.NavigationStack[0]).ToArray() : null; await navigation.PopToRootAsync(popInfo.WithAnimation); DisposePages(pagesToDispose); } break; case NavigationMode.Custom: await HandleCustomPopNavigation(popInfo); break; default: throw new NotImplementedException(); } }
Task HandleCustomPopNavigation(NavigationPopInfo popInfo) { // TODO: Implement your own navigation stack manipulation using popInfo return(Task.FromResult(0)); }