async Task PopToRootAsyncInner(bool animated) { if (StackDepth == 1) { return; } Element[] childrenToRemove = InternalChildren.Skip(1).ToArray(); foreach (Element child in childrenToRemove) { InternalChildren.Remove(child); } CurrentPage = RootPage; var args = new NavigationRequestedEventArgs(RootPage, animated); EventHandler <NavigationRequestedEventArgs> requestPopToRoot = PopToRootRequested; if (requestPopToRoot != null) { requestPopToRoot(this, args); if (args.Task != null) { await args.Task; } } PoppedToRoot?.Invoke(this, new PoppedToRootEventArgs(RootPage, childrenToRemove.OfType <Page>().ToList())); }
async Task SendHandlerUpdateAsync(bool animated, bool push = false, bool pop = false, bool popToRoot = false) { // Wait for any pending navigation tasks to finish await WaitForCurrentNavigationTask(); var completionSource = new TaskCompletionSource <object>(); CurrentNavigationTask = completionSource.Task; _taskCompletionSource = completionSource; // We create a new list to send to the handler because the structure backing // The Navigation stack isn't immutable var previousPage = CurrentPage; var immutableNavigationStack = new List <IView>(NavigationStack); // Alert currently visible pages that navigation is happening SendNavigating(); // Create the request for the handler var request = new NavigationRequest(immutableNavigationStack, animated); ((INavigationView)this).RequestNavigation(request); // Wait for the handler to finish processing the navigation await completionSource.Task; // Send navigated event to currently visible pages and associated navigation event SendNavigated(previousPage); if (push) { Pushed?.Invoke(this, new NavigationEventArgs(CurrentPage)); } else if (pop) { Popped?.Invoke(this, new NavigationEventArgs(previousPage)); } else { PoppedToRoot?.Invoke(this, new NavigationEventArgs(previousPage)); } }