protected override 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(); if (attribute.SharedElements != null) { foreach (var item in attribute.SharedElements) { string name = item.Key; if (string.IsNullOrEmpty(name)) { name = ViewCompat.GetTransitionName(item.Value); } ft.AddSharedElement(item.Value, name); } } 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 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); }
protected virtual Task <bool> ShowDialogFragment( Type view, MvxDialogFragmentPresentationAttribute attribute, MvxViewModelRequest request) { ValidateArguments(view, attribute, request); if (CurrentActivity == null) { throw new InvalidOperationException("CurrentActivity is null"); } if (CurrentFragmentManager == null) { throw new InvalidOperationException("CurrentFragmentManager is null. Cannot create Fragment Transaction."); } if (attribute.ViewType == null) { throw new InvalidOperationException($"{nameof(MvxDialogFragmentPresentationAttribute)}.ViewType is null"); } var fragmentName = attribute.Tag ?? 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 override bool CloseFragmentDialog(IMvxViewModel viewModel, MvxDialogFragmentPresentationAttribute attribute) { if (Dialogs.TryGetValue(viewModel, out DialogFragment dialog)) { dialog.DismissAllowingStateLoss(); dialog.Dispose(); Dialogs.Remove(viewModel); return(true); } return(false); }
protected virtual Task <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(Task.FromResult(true)); } return(Task.FromResult(false)); }
protected override 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(true); } return(false); }
protected override Task <bool> ShowDialogFragment(Type view, MvxDialogFragmentPresentationAttribute attribute, MvxViewModelRequest request) { var fragmentName = attribute.ViewType.FragmentJavaName(); var tag = attribute.Tag ?? fragmentName; IMvxFragmentView mvxFragmentView = CreateFragment(attribute, fragmentName); var dialog = mvxFragmentView as DialogFragment; if (dialog == null) { throw new MvxException("Fragment {0} does not extend {1}", fragmentName, typeof(DialogFragment).FullName); } // MvxNavigationService provides an already instantiated ViewModel here, // therefore just assign it if (request is MvxViewModelInstanceRequest instanceRequest) { mvxFragmentView.ViewModel = instanceRequest.ViewModelInstance; } else { mvxFragmentView.LoadViewModelFrom(request); } 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, tag); OnFragmentChanged(ft, dialog, attribute, request); return(Task.FromResult(true)); }
protected override Task <bool> CloseFragmentDialog(IMvxViewModel viewModel, MvxDialogFragmentPresentationAttribute attribute) { try { var fragmentName = attribute.ViewType.FragmentJavaName(); var tag = attribute.Tag ?? fragmentName; var toClose = CurrentFragmentManager.FindFragmentByTag(tag); if (toClose != null && toClose is DialogFragment dialog) { dialog.DismissAllowingStateLoss(); return(Task.FromResult(true)); } } catch (System.Exception ex) { MvxAndroidLog.Instance.Error("Cannot close fragment dialog", ex); return(Task.FromResult(false)); } return(Task.FromResult(false)); }
public override ValueTask<MvxBasePresentationAttribute?> CreatePresentationAttribute(Type? viewModelType, Type? viewType) { if (viewType?.IsSubclassOf(typeof(DialogFragment)) ?? false) { MvxLog.Instance.Trace("PresentationAttribute not found for {0}. Assuming DialogFragment presentation", viewType.Name); var attribute = new MvxDialogFragmentPresentationAttribute() { ViewType = viewType, ViewModelType = viewModelType }; return new ValueTask<MvxBasePresentationAttribute?>(attribute); } else if (viewType?.IsSubclassOf(typeof(Fragment)) ?? false) { MvxLog.Instance.Trace("PresentationAttribute not found for {0}. Assuming Fragment presentation", viewType.Name); var attribute= new MvxFragmentPresentationAttribute(GetCurrentActivityViewModelType(), global::Android.Resource.Id.Content) { ViewType = viewType, ViewModelType = viewModelType }; return new ValueTask<MvxBasePresentationAttribute?>(attribute); } else if (viewType?.IsSubclassOf(typeof(Activity)) ?? false) { MvxLog.Instance.Trace("PresentationAttribute not found for {0}. Assuming Activity presentation", viewType.Name); var attribute = new MvxActivityPresentationAttribute() { ViewType = viewType, ViewModelType = viewModelType }; return new ValueTask<MvxBasePresentationAttribute?>(attribute); } return new ValueTask<MvxBasePresentationAttribute?>((MvxBasePresentationAttribute?)null); }