/// <summary> /// Navigate back in current page modal navigation stack. /// </summary> /// <param name="closeModal">Close modal page</param> /// <param name="parameter">The navigation paremeter</param> public Task GoBackModalAsync(bool closeModal, object parameter = null) { ContentPage backOutPage = m_navigation.NavigationStack.LastOrDefault(); ContentPage backInPage = null; if (m_navigation.NavigationStack.Count > 2 && closeModal == false) { backInPage = m_navigation.NavigationStack.ElementAt(m_navigation.NavigationStack.Count - 2); } DissapearEventArgs dissapearArgs = new DissapearEventArgs(NavigationDirection.Out); AppearEventArgs appearArgs = new AppearEventArgs(NavigationDirection.In, parameter); NavigationPage.InvokeOnNavigationAwareElement(backOutPage, v => v.OnDissapearing(dissapearArgs)); NavigationPage.InvokeOnNavigationAwareElement(backInPage, v => v.OnAppearing(appearArgs)); return(m_navigation.PopModalAsync(closeModal).ContinueWith((arg) => { NavigationPage.InvokeOnNavigationAwareElement(backOutPage, v => v.OnDissapeared(dissapearArgs)); NavigationPage.InvokeOnNavigationAwareElement(backInPage, v => v.OnAppeared(appearArgs)); TaskCompletionSource <object> tcs = m_modalTaskDictionary[backOutPage]; m_modalTaskDictionary.Remove(backOutPage); tcs.SetResult(parameter); })); }
/// <summary> /// Page is appeared to screen and animation is finished /// </summary> public virtual void OnAppeared(AppearEventArgs args) { if (IsDebugEnabled) { Debug.WriteLine(NavigationBar.GetTitle(this) + ": OnAppeared"); } LifecycleState = LifecycleStates.Appeared; if (ContentCreateEvent == ContentCreateEvents.Appeared && ContentTemplate != null && Content is View == false && _contentElement == null) { if (_contentElement != null && Children.Contains(_contentElement)) { Children.Remove(_contentElement); } _contentElement = ContentTemplate.CreateContent() as View; Children.Insert(0, _contentElement); if (Content != null) { _contentElement.BindingContext = Content; } } }
/// <summary> /// Page is started to appearing on the screen with animation /// </summary> public virtual void OnAppearing(AppearEventArgs args) { if (IsDebugEnabled) { Debug.WriteLine(NavigationBar.GetTitle(this) + ": OnAppearing"); } LifecycleState = LifecycleStates.Appearing; }
/// <summary> /// Navigate to new modal page. If current page has modal pages visible, then modal pages is closed /// with current page. /// </summary> /// <param name="page">Page class name</param> /// <param name="parameter">The navigation parameter</param> public Task <object> NavigateModalAsync(string page, object parameter) { ContentPage currentModalPage = m_navigation.ModalNavigationStack.LastOrDefault(); ContentPage nextModalPage = m_createPage(page); DissapearEventArgs dissapearArgs = new DissapearEventArgs(NavigationDirection.Out); AppearEventArgs appearArgs = new AppearEventArgs(NavigationDirection.In, parameter); NavigationPage.InvokeOnNavigationAwareElement(currentModalPage, v => v.OnDissapearing(dissapearArgs)); NavigationPage.InvokeOnNavigationAwareElement(nextModalPage, v => v.OnAppearing(appearArgs)); m_navigation.PushModalAsync(nextModalPage).ContinueWith((arg) => { NavigationPage.InvokeOnNavigationAwareElement(currentModalPage, v => v.OnDissapeared(dissapearArgs)); NavigationPage.InvokeOnNavigationAwareElement(nextModalPage, v => v.OnAppeared(appearArgs)); }); TaskCompletionSource <object> tcs = new TaskCompletionSource <object>(); m_modalTaskDictionary.Add(nextModalPage, tcs); return(tcs.Task); }