private void PopFragment(FragmentManager fragmentManager, MvxFragmentPresentationAttribute fragmentAttribute, Fragment fragmentToPop) { var ft = fragmentManager.BeginTransaction(); 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(fragmentToPop); ft.CommitAllowingStateLoss(); OnFragmentPopped(ft, fragmentToPop, fragmentAttribute); }
protected virtual void PerformShowFragmentTransaction( FragmentManager fragmentManager, MvxFragmentPresentationAttribute attribute, MvxViewModelRequest request) { var fragmentName = attribute.ViewType.FragmentJavaName(); IMvxFragmentView fragment = null; if (attribute.IsCacheableFragment) { fragment = (IMvxFragmentView)fragmentManager.FindFragmentByTag(fragmentName); } fragment = fragment ?? CreateFragment(fragmentManager, attribute, attribute.ViewType); var fragmentView = fragment.ToFragment(); // MvxNavigationService provides an already instantiated ViewModel here if (request is MvxViewModelInstanceRequest instanceRequest) { fragment.ViewModel = instanceRequest.ViewModelInstance; } // save MvxViewModelRequest in the Fragment's Arguments var bundle = new Bundle(); var serializedRequest = NavigationSerializer.Serializer.SerializeObject(request); bundle.PutString(ViewModelRequestBundleKey, serializedRequest); if (fragmentView != null) { if (fragmentView.Arguments == null) { fragmentView.Arguments = bundle; } else { fragmentView.Arguments.Clear(); fragmentView.Arguments.PutAll(bundle); } } var ft = fragmentManager.BeginTransaction(); OnBeforeFragmentChanging(ft, fragmentView, attribute, request); if (attribute.AddToBackStack) { ft.AddToBackStack(fragmentName); } OnFragmentChanging(ft, fragmentView, attribute, request); ft.Replace(attribute.FragmentContentId, fragmentView, fragmentName); ft.CommitAllowingStateLoss(); OnFragmentChanged(ft, fragmentView, attribute, request); }
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, (int)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); }
private bool loadFragment(Fragment fragment) { if (fragment != null) { AndroidX.Fragment.App.FragmentTransaction ft = fm.BeginTransaction(); ft.SetCustomAnimations(Resource.Animation.fragment_open_enter, Resource.Animation.fragment_open_exit, Resource.Animation.abc_popup_enter, Resource.Animation.abc_popup_exit); ft.Replace(Resource.Id.fragmContainer, fragment).Commit(); return(true); } return(false); }
private void Bnve_NavigationItemSelected(object sender, BottomNavigationView.NavigationItemSelectedEventArgs e) { switch (e.Item.ItemId) { case Resource.Id.action_earning: fragmentManager.BeginTransaction() .Hide(activeFragment) .Show(earningsFragment) .Commit(); activeFragment = earningsFragment; break; case Resource.Id.action_home: fragmentManager.BeginTransaction() .Hide(activeFragment) .Show(homeFragment) .Commit(); activeFragment = homeFragment; break; case Resource.Id.action_rating: fragmentManager.BeginTransaction() .Hide(activeFragment) .Show(ratingsFragment) .Commit(); activeFragment = ratingsFragment; break; case Resource.Id.action_account: fragmentManager.BeginTransaction() .Hide(activeFragment) .Show(accountFragment) .Commit(); activeFragment = accountFragment; break; default: return; } }
private void LoadFragments() { activeFragment = homeFragment; fragmentManager = SupportFragmentManager; fragmentManager.BeginTransaction() .Add(containerId, homeFragment, "Home") .Commit(); fragmentManager.BeginTransaction() .Add(containerId, earningsFragment, "Earnings") .Hide(earningsFragment) .Commit(); fragmentManager.BeginTransaction() .Add(containerId, ratingsFragment, "Ratings") .Hide(ratingsFragment) .Commit(); fragmentManager.BeginTransaction() .Add(containerId, accountFragment, "Account") .Hide(accountFragment) .Commit(); }
public override void Show(FragmentManager manager, string tag) { try { var transaction = manager.BeginTransaction(); transaction.Add(this, Tag); transaction.CommitAllowingStateLoss(); } catch (IllegalStateException e) { // This sometimes fails for some reason, not sure why Logger.Error(e); } }
public void Initialize() { LatLng southwest = new LatLng(30, 118); CameraPosition.Builder builder = new CameraPosition.Builder(); CameraPosition cameraPosition = builder.Target(southwest).Zoom(2).Bearing(2.0f).Tilt(2.5f).Build(); HuaweiMapOptions huaweiMapOptions = new HuaweiMapOptions().InvokeCamera(cameraPosition); mSupportMapFragment = SupportMapFragment.NewInstance(huaweiMapOptions); mSupportMapFragment.GetMapAsync(this); AndroidX.Fragment.App.FragmentManager fragmentManager = SupportFragmentManager; AndroidX.Fragment.App.FragmentTransaction fragmentTransaction = fragmentManager.BeginTransaction(); fragmentTransaction.Add(Resource.Id.frame_supportmapcode, mSupportMapFragment); fragmentTransaction.Commit(); }
protected virtual Task <bool> CloseViewPagerFragment(IMvxViewModel viewModel, MvxViewPagerFragmentPresentationAttribute attribute) { ViewPager viewPager = null; FragmentManager fragmentManager = null; if (attribute?.FragmentHostViewType != null) { var fragment = GetFragmentByViewType(attribute.FragmentHostViewType); if (fragment == null) { throw new MvxException("Fragment not found", attribute.FragmentHostViewType.Name); } viewPager = fragment.View.FindViewById <ViewPager>(attribute.ViewPagerResourceId); fragmentManager = fragment.ChildFragmentManager; } else { viewPager = CurrentActivity.FindViewById <ViewPager>(attribute.ViewPagerResourceId); fragmentManager = CurrentFragmentManager; } if (viewPager?.Adapter is MvxCachingFragmentStatePagerAdapter adapter) { var ft = fragmentManager.BeginTransaction(); var fragmentInfo = FindFragmentInfoFromAttribute(attribute, adapter); var fragment = fragmentManager.FindFragmentByTag(fragmentInfo.Tag); adapter.FragmentsInfo.Remove(fragmentInfo); ft.Remove(fragment); ft.CommitAllowingStateLoss(); adapter.NotifyDataSetChanged(); OnFragmentPopped(ft, fragment, attribute); return(Task.FromResult(true)); } return(Task.FromResult(false)); }
protected virtual void PerformShowFragmentTransaction( FragmentManager fragmentManager, MvxFragmentPresentationAttribute attribute, MvxViewModelRequest request) { ValidateArguments(attribute, request); if (fragmentManager == null) { throw new ArgumentNullException(nameof(fragmentManager)); } var fragmentName = attribute.Tag ?? attribute.ViewType.FragmentJavaName(); IMvxFragmentView?fragmentView = null; if (attribute.IsCacheableFragment) { fragmentView = (IMvxFragmentView)fragmentManager.FindFragmentByTag(fragmentName); } if (fragmentView == null && attribute.ViewType != null) { fragmentView = CreateFragment(fragmentManager, attribute, attribute.ViewType); } var fragment = fragmentView.ToFragment(); if (fragment == null) { throw new MvxException($"Fragment {fragmentName} is null. Cannot perform Fragment Transaction."); } // MvxNavigationService provides an already instantiated ViewModel here if (request is MvxViewModelInstanceRequest instanceRequest) { fragmentView !.ViewModel = instanceRequest.ViewModelInstance; } // save MvxViewModelRequest in the Fragment's Arguments #pragma warning disable CA2000 // Dispose objects before losing scope var bundle = new Bundle(); #pragma warning restore CA2000 // Dispose objects before losing scope var serializedRequest = NavigationSerializer.Serializer.SerializeObject(request); bundle.PutString(ViewModelRequestBundleKey, serializedRequest); if (fragment.Arguments == null) { fragment.Arguments = bundle; } else { fragment.Arguments.Clear(); fragment.Arguments.PutAll(bundle); } var ft = fragmentManager.BeginTransaction(); OnBeforeFragmentChanging(ft, fragment, attribute, request); if (attribute.AddToBackStack) { ft.AddToBackStack(fragmentName); } OnFragmentChanging(ft, fragment, attribute, request); if (attribute.AddFragment && fragment.IsAdded) { ft.Show(fragment); } else if (attribute.AddFragment) { ft.Add(attribute.FragmentContentId, fragment, fragmentName); } else { ft.Replace(attribute.FragmentContentId, fragment, fragmentName); } ft.CommitAllowingStateLoss(); OnFragmentChanged(ft, fragment, attribute, request); }