/// <summary> /// A fragment transition animation has ended. /// </summary> /// <param name="enter">if set to <c>true</c> a new fragment has entered.</param> public void FragmentAnimationEnded(bool enter) { if (enter) { var oldFragment = Fragments.Count > 1 ? Fragments[Fragments.Count - 2] : null; var newFragment = Fragments.Last(); if (oldFragment != null) { oldFragment.OnFragmentDidHide(); oldFragment.View.Visibility = ViewStates.Invisible; } newFragment.OnFragmentDidShow(); } else { var newFragment = Fragments.Count > 1 ? Fragments[Fragments.Count - 2] : null; var oldFragment = Fragments.Last(); oldFragment.OnFragmentDidHide(); newFragment?.OnFragmentDidShow(); Fragments.Remove(Fragments.Last()); } InFragmentTransition = false; }
/// <summary> /// Pops the top-most fragment from the view stack. /// </summary> public void PopTopFragment() { if (Fragments.Count > 1) { var oldFragment = Fragments.Last(); var tx = FragmentManager.BeginTransaction(); tx.SetCustomAnimations(global::Android.Resource.Animator.FadeIn, global::Android.Resource.Animator.FadeOut, global::Android.Resource.Animator.FadeIn, global::Android.Resource.Animator.FadeOut); tx.Remove(oldFragment); InFragmentTransition = true; tx.Commit(); } }
/// <summary> /// Called to process key events. /// </summary> /// <param name="e">The key event.</param> public override bool DispatchKeyEvent(KeyEvent e) { // // If we are in the middle of a transition, ignore all keys. // if (InFragmentTransition == true) { return(true); } // // If we are currently loading a new action then disable everything // except the Back button. // if (LoadingCancellationTokenSource != null) { if (e.KeyCode == Keycode.Back) { if (!Fragments.Any()) { return(base.DispatchKeyEvent(e)); } LoadingCancellationTokenSource.Cancel(); LoadingCancellationTokenSource = null; HideLoading(); } return(true); } if (Fragments.Any()) { if (Fragments.Last().DispatchKeyEvent(e)) { return(true); } } return(base.DispatchKeyEvent(e)); }
/// <summary> /// A fragment transition animation has started. /// </summary> /// <param name="enter">if set to <c>true</c> a new fragment is entering.</param> public void FragmentAnimationStarted(bool enter) { if (enter) { var oldFragment = Fragments.Count > 1 ? Fragments[Fragments.Count - 2] : null; var newFragment = Fragments.Last(); oldFragment?.OnFragmentWillHide(); newFragment.OnFragmentWillShow(); } else { var newFragment = Fragments.Count > 1 ? Fragments[Fragments.Count - 2] : null; var oldFragment = Fragments.Last(); oldFragment.OnFragmentWillHide(); if (newFragment != null) { newFragment.OnFragmentWillShow(); newFragment.View.Visibility = ViewStates.Visible; } } }