Пример #1
0
        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);
        }
Пример #2
0
        private void PopOnBackstackEntries(
            string fragmentName, FragmentManager fragmentManager, MvxFragmentPresentationAttribute fragmentAttribute)
        {
            var popBackStackFragmentName =
                string.IsNullOrEmpty(fragmentAttribute.PopBackStackImmediateName?.Trim())
                    ? fragmentName
                    : fragmentAttribute.PopBackStackImmediateName;

            fragmentManager.PopBackStackImmediate(
                popBackStackFragmentName,
                (int)fragmentAttribute.PopBackStackImmediateFlag.ToNativePopBackStackFlags());

            OnFragmentPopped(null, null, fragmentAttribute);
        }