protected virtual void ShowDialogFragment( Type view, MvxDialogFragmentPresentationAttribute attribute, MvxViewModelRequest request) { var fragmentName = FragmentJavaName(attribute.ViewType); IMvxFragmentView mvxFragmentView = CreateFragment(attribute, fragmentName); var dialog = (DialogFragment)mvxFragmentView; // MvxNavigationService provides an already instantiated ViewModel here, // therefore just assign it if (request is MvxViewModelInstanceRequest instanceRequest) { mvxFragmentView.ViewModel = instanceRequest.ViewModelInstance; } else { mvxFragmentView.LoadViewModelFrom(request, null); } dialog.Cancelable = attribute.Cancelable; Dialogs.Add(mvxFragmentView.ViewModel, dialog); var ft = CurrentFragmentManager.BeginTransaction(); OnBeforeFragmentChanging(ft, attribute); if (attribute.AddToBackStack == true) { ft.AddToBackStack(fragmentName); } dialog.Show(ft, fragmentName); }
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(); }
public override void Show(MvxViewModelRequest request) { if (request.PresentationValues?["NavigationCommand"] == "StackClear") { CurrentFragmentManager.PopBackStack(); } base.Show(request); }
protected virtual void ShowDialogFragment( Type view, MvxDialogFragmentPresentationAttribute attribute, MvxViewModelRequest request) { var fragmentName = FragmentJavaName(attribute.ViewType); var dialog = (DialogFragment)CreateFragment(attribute, fragmentName); var mvxFragmentView = (IMvxFragmentView)dialog; // MvxNavigationService provides an already instantiated ViewModel here, // therefore just assign it if (request is MvxViewModelInstanceRequest instanceRequest) { mvxFragmentView.ViewModel = instanceRequest.ViewModelInstance; } else { mvxFragmentView.LoadViewModelFrom(request, null); } dialog.Cancelable = attribute.Cancelable; Dialogs.Add(mvxFragmentView.ViewModel, dialog); var ft = CurrentFragmentManager.BeginTransaction(); if (attribute.SharedElements != null) { foreach (var item in attribute.SharedElements) { ft.AddSharedElement(item.Value, item.Key); } } if (!attribute.EnterAnimation.Equals(int.MinValue) && !attribute.ExitAnimation.Equals(int.MinValue)) { if (!attribute.PopEnterAnimation.Equals(int.MinValue) && !attribute.PopExitAnimation.Equals(int.MinValue)) { ft.SetCustomAnimations(attribute.EnterAnimation, attribute.ExitAnimation, attribute.PopEnterAnimation, attribute.PopExitAnimation); } else { ft.SetCustomAnimations(attribute.EnterAnimation, attribute.ExitAnimation); } } if (attribute.TransitionStyle != int.MinValue) { ft.SetTransitionStyle(attribute.TransitionStyle); } if (attribute.AddToBackStack == true) { ft.AddToBackStack(fragmentName); } dialog.Show(ft, fragmentName); }
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 bool CloseFragments() { try { CurrentFragmentManager.PopBackStackImmediate(); } catch (System.Exception ex) { MvxLog.Instance.Trace("Cannot close any fragments", ex); } return(true); }
public override void Show(MvxViewModelRequest request) { if (request.PresentationValues?[Constants.NavigationCommandKey] == Constants.NavigationCommandClearStackValue) { for (int i = 0; i < CurrentFragmentManager.BackStackEntryCount; i++) { CurrentFragmentManager.PopBackStack(null, FragmentManager.PopBackStackInclusive); } } base.Show(request); }
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 virtual Fragment GetFragmentByViewType(Type type) { var fragmentName = type.FragmentJavaName(); var fragment = CurrentFragmentManager?.FindFragmentByTag(fragmentName); if (fragment != null) { return(fragment); } return(FindFragmentInChildren(fragmentName, CurrentFragmentManager)); }
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 abstract int ActivityLayout { get; } /// <summary> /// /// </summary> /// <param name="bundle"></param> protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(View); Injector.BuildUp(); CurrentFragmentManager.ClearBackStack(); ConfigureExitDialog(); SetupToolBar(Toolbar); NavigationView?.OnNavigationItemSelected() .Subscribe(e => OnNavigationItemSelected(e.EventArgs)) .ToBeDisposedBy(this); DrawerSetup(Drawer); }
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); }
public override Task <bool> ChangePresentation(MvxPresentationHint hint) { if (hint is MvxPagePresentationHint pagePresentationHint) { var request = new MvxViewModelRequest(pagePresentationHint.ViewModel); var attribute = GetPresentationAttribute(request); if (attribute is MvxBottomNavigationViewPresentationAttribute bottomNavigationAttribute) { MvxBottomNavigationView bottomNavigationView = FindMvxBottomNavigationViewInFragmentPresentation(bottomNavigationAttribute); if (bottomNavigationView != null) { var menuItem = bottomNavigationView.FindItemByViewModel(pagePresentationHint.ViewModel); if (menuItem == null) { //MvvmCross.MvxAndroidLog.Instance.Trace("Did not find a menu item which corresponds to {0}, skipping presentation change...", pagePresentationHint.ViewModel); return(Task.FromResult(false)); } // If we are deeper in our back stack, we want to make sure that we remove the stack if (CurrentFragmentManager.BackStackEntryCount > 0) { var name = CurrentFragmentManager.GetBackStackEntryAt(0).Name; CurrentFragmentManager.PopBackStackImmediate(name, 1); } PerformShowFragmentTransaction(CurrentFragmentManager, bottomNavigationAttribute, new MvxViewModelRequest(pagePresentationHint.ViewModel)); var item = bottomNavigationView.FindItemByViewModel(pagePresentationHint.ViewModel); item.SetChecked(true); return(Task.FromResult(true)); } } } return(base.ChangePresentation(hint)); }
protected virtual Task <bool> ShowDialogFragment( Type view, MvxDialogFragmentPresentationAttribute attribute, MvxViewModelRequest request) { var fragmentName = attribute.ViewType.FragmentJavaName(); IMvxFragmentView mvxFragmentView = CreateFragment(CurrentActivity.SupportFragmentManager, attribute, attribute.ViewType); var dialog = (DialogFragment)mvxFragmentView; // MvxNavigationService provides an already instantiated ViewModel here, // therefore just assign it if (request is MvxViewModelInstanceRequest instanceRequest) { mvxFragmentView.ViewModel = instanceRequest.ViewModelInstance; } else { mvxFragmentView.LoadViewModelFrom(request, null); } dialog.Cancelable = attribute.Cancelable; var ft = CurrentFragmentManager.BeginTransaction(); OnBeforeFragmentChanging(ft, dialog, attribute, request); if (attribute.AddToBackStack) { ft.AddToBackStack(fragmentName); } OnFragmentChanging(ft, dialog, attribute, request); dialog.Show(ft, fragmentName); OnFragmentChanged(ft, dialog, attribute, request); return(Task.FromResult(true)); }
protected virtual Fragment GetFragmentByViewType(Type type) { var fragmentName = FragmentJavaName(type); return(CurrentFragmentManager.FindFragmentByTag(fragmentName)); }
protected virtual bool IsDeadLocked(IDialog dialog) { return(CurrentFragmentManager.IsBackStackEmpty(0) && dialog == null || dialog.IsDeadLocked()); }