private void InvokeFragmentTransaction(FragmentInfo fragmentInfo) { if (fragmentInfo.FragmentInstance == _currentFragment) { return; } var fragmentTransaction = CurrentFragmentManager.BeginTransaction(); var fragment = fragmentInfo.FragmentInstance; fragment.ViewModel = fragmentInfo.ViewModelInstance; if (CurrentFragmentManager.FindFragmentByTag(fragmentInfo.JavaFragmentName) != null) { fragmentTransaction.Show(CurrentFragmentManager.FindFragmentByTag( fragmentInfo.JavaFragmentName)); } else { fragmentTransaction.Add(fragmentInfo.FragmentContentId, (Fragment)fragment, fragmentInfo.JavaFragmentName); } fragmentTransaction.Commit(); fragmentTransaction = CurrentFragmentManager.BeginTransaction(); if (_currentFragment != null) { fragmentTransaction.Hide(_currentFragment); } fragmentTransaction.Commit(); _currentFragment = (Fragment)fragment; fragmentInfo.ViewModelInstance.ViewAppearing(); }
protected virtual bool TryPerformCloseFragmentTransaction( FragmentManager fragmentManager, MvxFragmentPresentationAttribute fragmentAttribute) { try { var fragmentName = fragmentAttribute.ViewType.FragmentJavaName(); if (fragmentManager.BackStackEntryCount > 0) { var popBackStackFragmentName = fragmentAttribute.PopBackStackImmediateName?.Trim() == "" ? fragmentName : fragmentAttribute.PopBackStackImmediateName; fragmentManager.PopBackStackImmediate(popBackStackFragmentName, fragmentAttribute.PopBackStackImmediateFlag.ToNativePopBackStackFlags()); OnFragmentPopped(null, null, fragmentAttribute); return(true); } else if (CurrentFragmentManager.FindFragmentByTag(fragmentName) != null) { var ft = fragmentManager.BeginTransaction(); var fragment = fragmentManager.FindFragmentByTag(fragmentName); if (!fragmentAttribute.EnterAnimation.Equals(int.MinValue) && !fragmentAttribute.ExitAnimation.Equals(int.MinValue)) { if (!fragmentAttribute.PopEnterAnimation.Equals(int.MinValue) && !fragmentAttribute.PopExitAnimation.Equals(int.MinValue)) { ft.SetCustomAnimations(fragmentAttribute.EnterAnimation, fragmentAttribute.ExitAnimation, fragmentAttribute.PopEnterAnimation, fragmentAttribute.PopExitAnimation); } else { ft.SetCustomAnimations(fragmentAttribute.EnterAnimation, fragmentAttribute.ExitAnimation); } } if (fragmentAttribute.TransitionStyle != int.MinValue) { ft.SetTransitionStyle(fragmentAttribute.TransitionStyle); } ft.Remove(fragment); ft.CommitAllowingStateLoss(); OnFragmentPopped(ft, fragment, fragmentAttribute); return(true); } } catch (System.Exception ex) { MvxLog.Instance.Error("Cannot close fragment transaction", ex); return(false); } return(false); }
protected virtual ValueTask<bool> CloseFragmentDialog(IMvxViewModel viewModel, MvxDialogFragmentPresentationAttribute? attribute) { string? tag = attribute?.ViewType?.FragmentJavaName(); var toClose = CurrentFragmentManager.FindFragmentByTag(tag); if (toClose != null && toClose is DialogFragment dialog) { dialog.DismissAllowingStateLoss(); return new ValueTask<bool>(true); } return new ValueTask<bool>(false); }
protected virtual Fragment GetFragmentByViewType(Type type) { var fragmentName = type.FragmentJavaName(); var fragment = CurrentFragmentManager?.FindFragmentByTag(fragmentName); if (fragment != null) { return(fragment); } return(FindFragmentInChildren(fragmentName, CurrentFragmentManager)); }
protected virtual Task <bool> CloseFragmentDialog(IMvxViewModel viewModel, MvxDialogFragmentPresentationAttribute attribute) { string tag = FragmentJavaName(attribute.ViewType); var toClose = CurrentFragmentManager.FindFragmentByTag(tag); if (toClose != null && toClose is DialogFragment dialog) { dialog.DismissAllowingStateLoss(); return(Task.FromResult(true)); } return(Task.FromResult(false)); }
protected override bool CloseFragmentDialog(IMvxViewModel viewModel, MvxDialogFragmentPresentationAttribute attribute) { var tag = FragmentJavaName(attribute.ViewType); var toClose = CurrentFragmentManager?.FindFragmentByTag(tag); if (toClose is DialogFragment dialog) { dialog.DismissAllowingStateLoss(); return(true); } return(false); }
protected virtual bool TryPerformCloseFragmentTransaction( FragmentManager fragmentManager, MvxFragmentPresentationAttribute fragmentAttribute) { var fragmentName = fragmentAttribute.ViewType.FragmentJavaName(); if (fragmentManager.BackStackEntryCount > 0) { fragmentManager.PopBackStackImmediate(fragmentName, PopBackStackFlags.Inclusive); OnFragmentPopped(null, null, fragmentAttribute); return(true); } else if (CurrentFragmentManager.FindFragmentByTag(fragmentName) != null) { var ft = fragmentManager.BeginTransaction(); var fragment = fragmentManager.FindFragmentByTag(fragmentName); if (!fragmentAttribute.EnterAnimation.Equals(int.MinValue) && !fragmentAttribute.ExitAnimation.Equals(int.MinValue)) { if (!fragmentAttribute.PopEnterAnimation.Equals(int.MinValue) && !fragmentAttribute.PopExitAnimation.Equals(int.MinValue)) { ft.SetCustomAnimations(fragmentAttribute.EnterAnimation, fragmentAttribute.ExitAnimation, fragmentAttribute.PopEnterAnimation, fragmentAttribute.PopExitAnimation); } else { ft.SetCustomAnimations(fragmentAttribute.EnterAnimation, fragmentAttribute.ExitAnimation); } } if (fragmentAttribute.TransitionStyle != int.MinValue) { ft.SetTransitionStyle(fragmentAttribute.TransitionStyle); } ft.Remove(fragment); ft.CommitAllowingStateLoss(); OnFragmentPopped(ft, fragment, fragmentAttribute); return(true); } return(false); }
protected virtual Fragment GetFragmentByViewType(Type type) { var fragmentName = FragmentJavaName(type); return(CurrentFragmentManager.FindFragmentByTag(fragmentName)); }