Beispiel #1
0
        private async Task AnimateNavigatedToAsync(IPageAnimation pageAnimation, NavigationMode navigationMode, FrameworkElement previousPage, FrameworkElement nextPage)
        {
            if (IsFirstPage && ShowNavigationOnAppInAndOut && (navigationMode == NavigationMode.New || navigationMode == NavigationMode.Forward))
            {
                if (nextPage != null)
                {
                    nextPage.Opacity = 1;
                }
                return;
            }

            if (pageAnimation != null)
            {
                if (navigationMode == NavigationMode.Back)
                {
                    await pageAnimation.AnimateBackwardNavigatedToAsync(previousPage, nextPage);
                }
                else if (navigationMode != NavigationMode.Refresh)
                {
                    await pageAnimation.AnimateForwardNavigatedToAsync(previousPage, nextPage);
                }
            }

            if (nextPage != null)
            {
                nextPage.Opacity = 1;
            }
        }
Beispiel #2
0
 public static AnimationsId GetAnimationsId(IPageAnimation animation, bool isPush)
 {
     if (animation.Type == AnimationType.Push)
     {
         return(GetPushAnimationsId(animation, isPush));
     }
     if (animation.Type == AnimationType.Slide)
     {
         return(GetSlideAnimationsId(animation, isPush));
     }
     if (animation.Type == AnimationType.Fade)
     {
         return(GetFadeAnimationsId(animation, isPush));
     }
     if (animation.Type == AnimationType.Landing)
     {
         return(GetLandingAnimationsId(animation, isPush));
     }
     if (animation.Type == AnimationType.Roll)
     {
         return(GetRollAnimationsId(animation, isPush));
     }
     if (animation.Type == AnimationType.Rotate)
     {
         return(GetRotateAnimationsId(animation, isPush));
     }
     return(AnimationsId.Empty);
 }
Beispiel #3
0
        private static AnimationsId GetFadeAnimationsId(IPageAnimation animation, bool isPush)
        {
            switch (animation.Subtype)
            {
            case AnimationSubtype.FromLeft:
                return(isPush ? AnimationsId.Create(animation.BounceEffect ? Resource.Animator.enter_scale_from_left_short_bounce : Resource.Animator.enter_scale_from_left_short, Resource.Animator.empty_Animation_short) :
                       AnimationsId.Create(Resource.Animator.empty_Animation_short, Resource.Animator.exit_scale_from_left_short));

            case AnimationSubtype.FromRight:
                return(isPush ? AnimationsId.Create(animation.BounceEffect ? Resource.Animator.enter_scale_from_right_short_bounce : Resource.Animator.enter_scale_from_right_short, Resource.Animator.empty_Animation_short) :
                       AnimationsId.Create(Resource.Animator.empty_Animation_short, Resource.Animator.exit_scale_from_right_short));

            case AnimationSubtype.FromTop:
                return(isPush ? AnimationsId.Create(animation.BounceEffect ? Resource.Animator.enter_scale_from_top_short_bounce : Resource.Animator.enter_scale_from_top_short, Resource.Animator.empty_Animation_short) :
                       AnimationsId.Create(Resource.Animator.empty_Animation_short, Resource.Animator.exit_scale_from_top_short));

            case AnimationSubtype.FromBottom:
                return(isPush ? AnimationsId.Create(animation.BounceEffect ? Resource.Animator.enter_scale_from_bottom_short_bounce : Resource.Animator.enter_scale_from_bottom_short, Resource.Animator.empty_Animation_short) :
                       AnimationsId.Create(Resource.Animator.empty_Animation_short, Resource.Animator.exit_scale_from_bottom_short));

            default:
                return(isPush ? AnimationsId.Create(animation.BounceEffect ? Resource.Animator.enter_scale_short_bounce : Resource.Animator.enter_scale_short, Resource.Animator.empty_Animation_short) :
                       AnimationsId.Create(Resource.Animator.empty_Animation_short, Resource.Animator.exit_scale_short));
            }
        }
Beispiel #4
0
        private static AnimationsId GetRotateAnimationsId(IPageAnimation animation, bool isPush)
        {
            switch (animation.Subtype)
            {
            case AnimationSubtype.FromRight:
                return(isPush ? AnimationsId.Create(animation.BounceEffect ? Resource.Animator.enter_rotate_from_right_bounce : Resource.Animator.enter_rotate_from_right, Resource.Animator.empty_Animation) :
                       AnimationsId.Create(Resource.Animator.empty_Animation, Resource.Animator.exit_rotate_to_right));

            case AnimationSubtype.FromTop:
                return(isPush ? AnimationsId.Create(animation.BounceEffect ? Resource.Animator.enter_rotate_from_top_bounce : Resource.Animator.enter_rotate_from_top, Resource.Animator.empty_Animation) :
                       AnimationsId.Create(Resource.Animator.empty_Animation, Resource.Animator.exit_rotate_to_top));

            case AnimationSubtype.FromBottom:
                return(isPush ? AnimationsId.Create(animation.BounceEffect ? Resource.Animator.enter_rotate_from_bottom_bounce : Resource.Animator.enter_rotate_from_bottom, Resource.Animator.empty_Animation) :
                       AnimationsId.Create(Resource.Animator.empty_Animation, Resource.Animator.exit_rotate_to_bottom));

            case AnimationSubtype.FromLeft:
                return(isPush ? AnimationsId.Create(animation.BounceEffect ? Resource.Animator.enter_rotate_from_left_bounce : Resource.Animator.enter_rotate_from_left, Resource.Animator.empty_Animation) :
                       AnimationsId.Create(Resource.Animator.empty_Animation, Resource.Animator.exit_rotate_to_left));

            default:
                return(isPush ? AnimationsId.Create(animation.BounceEffect ? Resource.Animator.enter_rotate_bounce : Resource.Animator.enter_rotate, Resource.Animator.empty_Animation) :
                       AnimationsId.Create(Resource.Animator.empty_Animation, Resource.Animator.exit_rotate));
            }
        }
Beispiel #5
0
        private static AnimationsId GetLandingAnimationsId(IPageAnimation animation, bool isPush)
        {
            switch (animation.Subtype)
            {
            case AnimationSubtype.FromLeft:
                return(isPush ? AnimationsId.Create(animation.BounceEffect ? Resource.Animator.enter_landing_from_left_long_bounce : Resource.Animator.enter_landing_from_left_long, Resource.Animator.empty_Animation_long) :
                       AnimationsId.Create(Resource.Animator.empty_Animation_long, Resource.Animator.exit_landing_from_left_long));

            case AnimationSubtype.FromRight:
                return(isPush ? AnimationsId.Create(animation.BounceEffect ? Resource.Animator.enter_landing_from_right_long_bounce : Resource.Animator.enter_landing_from_right_long, Resource.Animator.empty_Animation_long) :
                       AnimationsId.Create(Resource.Animator.empty_Animation_long, Resource.Animator.exit_landing_from_right_long));

            case AnimationSubtype.FromTop:
                return(isPush ? AnimationsId.Create(animation.BounceEffect ? Resource.Animator.enter_landing_from_top_long_bounce : Resource.Animator.enter_landing_from_top_long, Resource.Animator.empty_Animation_long) :
                       AnimationsId.Create(Resource.Animator.empty_Animation_long, Resource.Animator.exit_landing_from_top_long));

            case AnimationSubtype.FromBottom:
                return(isPush ? AnimationsId.Create(animation.BounceEffect ? Resource.Animator.enter_landing_from_bottom_long_bounce : Resource.Animator.enter_landing_from_bottom_long, Resource.Animator.empty_Animation_long) :
                       AnimationsId.Create(Resource.Animator.empty_Animation_long, Resource.Animator.exit_landing_from_bottom_long));

            default:
                return(isPush ? AnimationsId.Create(animation.BounceEffect ? Resource.Animator.enter_landing_long_bounce : Resource.Animator.enter_landing_long, Resource.Animator.empty_Animation_long) :
                       AnimationsId.Create(Resource.Animator.empty_Animation_long, Resource.Animator.exit_landing_long));
            }
        }
Beispiel #6
0
 public SingleSample(string name, char icon, Type pageType, IPageAnimation animation, bool showBadge = false)
 {
     Name           = name;
     Icon           = icon;
     Animation      = animation;
     SamplePageType = pageType;
     ShowBadge      = showBadge;
 }
Beispiel #7
0
 public static void SetupTransition(FragmentTransaction transaction, IPageAnimation animation, bool isPush, bool animated)
 {
     if (animation.Type != AnimationType.Empty && animation.Duration != AnimationDuration.Zero)
     {
         var animationsId = GetAnimationsId(animation, isPush);
         transaction.SetCustomAnimations(animationsId.EnterAnimationId, animationsId.ExitAnimationId);
     }
 }
 private void PrepareToSwitch(IXPage page, IPageAnimation animation, bool isPop)
 {
     Context.HideKeyboard(this);
     CancelCurrentAnimation();
     ((isPop ? _currentPage.XamarinPage : page.XamarinPage) as IAnimationPage)?.OnAnimationStarted(isPop);
     SetNavAnimationInProgress(true);
     page.SetUIParams(animation.GetStartUIForAppearingPage(isPop));
     _currentPage.SetUIParams(animation.GetStartUIForDisappearingPage(isPop));
 }
Beispiel #9
0
        private static void RunCAAnimation(UIView view, IPageAnimation animation, bool isPop)
        {
            var transition = CATransition.CreateAnimation();

            transition.Duration       = GetDuration(animation.Duration);
            transition.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
            SetCAAnimationType(transition, animation, isPop);
            view.Layer.AddAnimation(transition, null);
        }
        public Page3()
        {
            InitializeComponent();

            PageAnimation = new RollPageAnimation
            {
                Duration = AnimationDuration.Long,
                Subtype  = AnimationSubtype.FromBottom
            };
        }
        public Page2()
        {
            InitializeComponent();

            PageAnimation = new FadePageAnimation
            {
                Duration = AnimationDuration.Long,
                Subtype  = AnimationSubtype.FromRight
            };
        }
        public Page1()
        {
            InitializeComponent();

            PageAnimation = new SlidePageAnimation
            {
                Duration = AnimationDuration.Long,
                Subtype  = AnimationSubtype.FromTop
            };
        }
 public AnimationPageViewModel(INavigation navigation, IPageAnimation animation, string title)
 {
     _navigation                = navigation;
     _animation                 = animation;
     PageTitle                  = title;
     ButtonClickedCommand       = new Command <AnimationSubtype>(OnButtonClicked);
     PageAppearingCommand       = new Command <Slider>(OnPageAppearing);
     DurationChangedCommand     = new Command <ValueChangedEventArgs> (OnDurationChangedCommand);
     BounceEffectChangedCommand = new Command <Switch> (OnBounceEffectChangedCommand);
     Duration = Utils.GetAnimationDurationProperty();
 }
Beispiel #14
0
 private static AnimationsId GetAnimationsId(IPageAnimation animation, bool isPush)
 {
     if (animation.Duration == AnimationDuration.Short)
     {
         return(SlowAnimationsId.GetAnimationsId(animation, isPush));
     }
     if (animation.Duration == AnimationDuration.Long)
     {
         return(LongAnimationsId.GetAnimationsId(animation, isPush));
     }
     return(NormalAnimationsId.GetAnimationsId(animation, isPush));
 }
 private Task <bool> SwitchAnimationPageAsync(IXPage xPage, IPageAnimation animation, bool isPop)
 {
     PrepareToSwitch(xPage, animation, isPop);
     _tcs = new TaskCompletionSource <bool>();
     if (animation.Type == AnimationType.Flip)
     {
         _currentAnimations.Add(_currentPage.GetDroidAnimation(animation, animation.GetEndUIForDisappearingPage(isPop), () => OnNewPageIsAppearing(xPage, animation, isPop), isPop));
     }
     else
     {
         OnNewPageIsAppearing(xPage, animation, isPop);
     }
     return(_tcs.Task);
 }
Beispiel #16
0
        private static void RunUIAnimation(IAnimationPage page, UIView view, IPageAnimation animation, bool isPop)
        {
            page?.OnAnimationStarted(isPop);
            var duration = GetDuration(animation.Duration) / 1000d;

            UIView.BeginAnimations(string.Empty);
            UIView.SetAnimationDuration(duration);
            UIView.SetAnimationTransition(GetUITransitionType(animation, isPop), view, true);
            UIView.CommitAnimations();
            Xamarin.Forms.Device.StartTimer(System.TimeSpan.FromSeconds(duration), delegate
            {
                page?.OnAnimationFinished(isPop);
                return(false);
            });
        }
Beispiel #17
0
 private async Task AnimateNavigatedFromIfCurrentPageNotNull(IPageAnimation pageAnimation, NavigationMode navigationMode,
                                                             PageInsertionMode insertionMode, MtPageDescription currentPage, MtPageDescription newPage)
 {
     if (currentPage != null)
     {
         if (insertionMode != PageInsertionMode.Sequential)
         {
             await AnimateNavigatingFromAsync(pageAnimation, navigationMode,
                                              currentPage.GetPage(this).ActualAnimationContext,
                                              insertionMode != PageInsertionMode.Sequential?newPage.GetPage(this).ActualAnimationContext : null);
         }
         else
         {
             await AnimateNavigatingFromAsync(pageAnimation, navigationMode, currentPage.GetPage(this).ActualAnimationContext, null);
         }
     }
 }
Beispiel #18
0
        private double GetAnimationDuration(IPageAnimation animation)
        {
            switch (animation.Duration)
            {
            case AnimationDuration.Short:
                return(Durations.ShortDuration);

            case AnimationDuration.Medium:
                return(Durations.MediumDuration);

            case AnimationDuration.Long:
                return(Durations.LongDuration);

            default:
                return(Durations.ZeroDuration);
            }
        }
Beispiel #19
0
        private async Task AnimateNavigatingFromAsync(IPageAnimation pageAnimation, NavigationMode navigationMode, FrameworkElement previousPage, FrameworkElement nextPage)
        {
            if (IsFirstPage && ShowNavigationOnAppInAndOut && navigationMode == NavigationMode.Back)
            {
                return;
            }

            if (pageAnimation != null)
            {
                if (navigationMode == NavigationMode.Back)
                {
                    await pageAnimation.AnimateBackwardNavigatingFromAsync(previousPage, nextPage);
                }
                else if (navigationMode != NavigationMode.Refresh)
                {
                    await pageAnimation.AnimateForwardNavigatingFromAsync(previousPage, nextPage);
                }
            }
        }
Beispiel #20
0
        private async Task AnimateNavigatedToAndRemoveCurrentPageAsync(IPageAnimation pageAnimation, NavigationMode navigationMode, PageInsertionMode insertionMode, MtPageDescription currentPage, MtPageDescription newPage)
        {
            if (currentPage != null)
            {
                if (insertionMode != PageInsertionMode.Sequential)
                {
                    await AnimateNavigatedToAsync(pageAnimation, navigationMode,
                                                  currentPage.GetPage(this).ActualAnimationContext,
                                                  newPage.GetPage(this).ActualAnimationContext);

                    ContentGrid.Children.Remove(currentPage.GetPage(this).InternalPage);
                }
                else
                {
                    await AnimateNavigatedToAsync(pageAnimation, navigationMode, null,
                                                  newPage.GetPage(this).ActualAnimationContext);
                }
            }
        }
Beispiel #21
0
        private static void SetCAAnimationType(CATransition transition, IPageAnimation animation, bool isPop)
        {
            switch (animation.Type)
            {
            case AnimationType.Fade:
                transition.Type = CAAnimation.TransitionFade;
                break;

            case AnimationType.Push:
                transition.Type    = CAAnimation.TransitionPush;
                transition.Subtype = GetCATransitionSubtype(animation.Subtype, isPop);
                break;

            case AnimationType.Slide:
                transition.Type    = isPop ? CAAnimation.TransitionReveal : CAAnimation.TransitionMoveIn;
                transition.Subtype = GetCATransitionSubtype(animation.Subtype, isPop);
                break;
            }
        }
Beispiel #22
0
        private static UIViewAnimationTransition GetUITransitionType(IPageAnimation animation, bool isPop)
        {
            switch (animation.Subtype)
            {
            case AnimationSubtype.FromTop:
                return(isPop ? UIViewAnimationTransition.CurlUp : UIViewAnimationTransition.CurlDown);

            case AnimationSubtype.FromBottom:
                return(isPop ? UIViewAnimationTransition.CurlDown : UIViewAnimationTransition.CurlUp);

            case AnimationSubtype.Default:
            case AnimationSubtype.FromLeft:
                return(isPop ? UIViewAnimationTransition.FlipFromRight : UIViewAnimationTransition.FlipFromLeft);

            case AnimationSubtype.FromRight:
                return(isPop ? UIViewAnimationTransition.FlipFromLeft : UIViewAnimationTransition.FlipFromRight);
            }
            return(UIViewAnimationTransition.None);
        }
Beispiel #23
0
        public ViewPropertyAnimator GetDroidAnimation(IPageAnimation animation, UIParams uiParams, Action onEndHandler, bool isPop)
        {
            var animatorListener = new GenericAnimatorListener();

            if (onEndHandler != null)
            {
                animatorListener.OnEnd = animatorListener.OnCancel = a => onEndHandler();
            }
            var anim = pageContainer.Animate().Alpha(uiParams.Alpha).SetDuration(GetDuration(animation.Duration)).
                       ScaleX(uiParams.ScaleX).ScaleY(uiParams.ScaleY).
                       Rotation(uiParams.RotationZ).RotationX(uiParams.RotationX).RotationY(uiParams.RotationY).
                       TranslationX(uiParams.TranslationX).TranslationY(uiParams.TranslationY).
                       SetListener(animatorListener);

            if (animation.BounceEffect)
            {
                anim.SetInterpolator(isPop ? _accelerateInterpolator : _bounceInterpolator);
            }
            return(anim);
        }
        private void OnNewPageIsAppearing(IXPage xPage, IPageAnimation animation, bool isPop)
        {
            ProcessPageAppearing(xPage, isPop);
            var pageForAnimation   = animation.Type != AnimationType.Flip && isPop ? _currentPage : xPage;
            var paramsForAnimation = animation.GetEndUIParamsWhenNewPageIsAppearing(isPop);

            _currentAnimations.Add(pageForAnimation.GetDroidAnimation(animation, paramsForAnimation, () =>
            {
                ((isPop ? _currentPage.XamarinPage : xPage.XamarinPage) as IAnimationPage)?.OnAnimationFinished(isPop);
                ProcessPageDisappearing(isPop);
                _currentPage = xPage;
                _tcs.TrySetResult(true);
            }, isPop));

            if (animation.Type == AnimationType.Push)
            {
                var animPage   = isPop ? xPage : _currentPage;
                var animParams = isPop ? animation.GetEndUIForAppearingPage(isPop) : animation.GetEndUIForDisappearingPage(isPop);
                _currentAnimations.Add(animPage.GetDroidAnimation(animation, animParams, null, isPop));
            }
        }
Beispiel #25
0
        private static AnimationsId GetPushAnimationsId(IPageAnimation animation, bool isPush)
        {
            switch (animation.Subtype)
            {
            case AnimationSubtype.FromRight:
                if (animation.BounceEffect && isPush)
                {
                    return(AnimationsId.Create(Resource.Animator.enter_from_right_short_bounce, Resource.Animator.exit_to_left_short_bounce));
                }
                return(isPush ? AnimationsId.Create(Resource.Animator.enter_from_right_short, Resource.Animator.exit_to_left_short) :
                       AnimationsId.Create(Resource.Animator.enter_from_left_short, Resource.Animator.exit_to_right_short));

            case AnimationSubtype.FromTop:
                if (animation.BounceEffect && isPush)
                {
                    return(AnimationsId.Create(Resource.Animator.enter_from_top_short_bounce, Resource.Animator.exit_to_bottom_short_bounce));
                }
                return(isPush ? AnimationsId.Create(Resource.Animator.enter_from_top_short, Resource.Animator.exit_to_bottom_short) :
                       AnimationsId.Create(Resource.Animator.enter_from_bottom_short, Resource.Animator.exit_to_top_short));

            case AnimationSubtype.FromBottom:
                if (animation.BounceEffect && isPush)
                {
                    return(AnimationsId.Create(Resource.Animator.enter_from_bottom_short_bounce, Resource.Animator.exit_to_top_short_bounce));
                }
                return(isPush ? AnimationsId.Create(Resource.Animator.enter_from_bottom_short, Resource.Animator.exit_to_top_short) :
                       AnimationsId.Create(Resource.Animator.enter_from_top_short, Resource.Animator.exit_to_bottom_short));

            default:
                if (animation.BounceEffect && isPush)
                {
                    return(AnimationsId.Create(Resource.Animator.enter_from_left_short_bounce, Resource.Animator.exit_to_right_short_bounce));
                }
                return(isPush ? AnimationsId.Create(Resource.Animator.enter_from_left_short, Resource.Animator.exit_to_right_short) :
                       AnimationsId.Create(Resource.Animator.enter_from_right_short, Resource.Animator.exit_to_left_short));
            }
        }
Beispiel #26
0
        private async Task AnimateNavigatingFromAsync(IPageAnimation pageAnimation, NavigationMode navigationMode, FrameworkElement previousPage, FrameworkElement nextPage)
        {
            if (IsFirstPage && ShowNavigationOnAppInAndOut && navigationMode == NavigationMode.Back)
                return;

            if (pageAnimation != null)
            {
                if (navigationMode == NavigationMode.Back)
                    await pageAnimation.AnimateBackwardNavigatingFromAsync(previousPage, nextPage);
                else if (navigationMode != NavigationMode.Refresh)
                    await pageAnimation.AnimateForwardNavigatingFromAsync(previousPage, nextPage);
            }
        }
        private Task <bool> SwitchContentAsync(Page page, IPageAnimation animation, bool isPop = true)
        {
            var xPage = page.GetXPage();

            return(animation.Type != AnimationType.Empty ? SwitchAnimationPageAsync(xPage, animation, isPop) : SwitchPageAsync(xPage, isPop));
        }
Beispiel #28
0
 private async Task AnimateNavigatedFromIfCurrentPageNotNull(IPageAnimation pageAnimation, NavigationMode navigationMode,
     PageInsertionMode insertionMode, MtPageDescription currentPage, MtPageDescription newPage)
 {
     if (currentPage != null)
     {
         if (insertionMode != PageInsertionMode.Sequential)
         {
             await AnimateNavigatingFromAsync(pageAnimation, navigationMode,
                 currentPage.GetPage(this).ActualAnimationContext,
                 insertionMode != PageInsertionMode.Sequential ? newPage.GetPage(this).ActualAnimationContext : null);
         }
         else
         {
             await AnimateNavigatingFromAsync(pageAnimation, navigationMode, currentPage.GetPage(this).ActualAnimationContext, null);
         }
     }
 }
Beispiel #29
0
        private async Task AnimateNavigatedToAndRemoveCurrentPageAsync(IPageAnimation pageAnimation, NavigationMode navigationMode, PageInsertionMode insertionMode, MtPageDescription currentPage, MtPageDescription newPage)
        {
            if (currentPage != null)
            {
                if (insertionMode != PageInsertionMode.Sequential)
                {
                    await AnimateNavigatedToAsync(pageAnimation, navigationMode,
                        currentPage.GetPage(this).ActualAnimationContext,
                        newPage.GetPage(this).ActualAnimationContext);

                    ContentGrid.Children.Remove(currentPage.GetPage(this).InternalPage);
                }
                else
                {
                    await AnimateNavigatedToAsync(pageAnimation, navigationMode, null,
                        newPage.GetPage(this).ActualAnimationContext);
                }
            }
        }
Beispiel #30
0
        private async Task AnimateNavigatedToAsync(IPageAnimation pageAnimation, NavigationMode navigationMode, FrameworkElement previousPage, FrameworkElement nextPage)
        {
            if (IsFirstPage && ShowNavigationOnAppInAndOut && (navigationMode == NavigationMode.New || navigationMode == NavigationMode.Forward))
            {
                if (nextPage != null)
                    nextPage.Opacity = 1;
                return;
            }

            if (pageAnimation != null)
            {
                if (navigationMode == NavigationMode.Back)
                    await pageAnimation.AnimateBackwardNavigatedToAsync(previousPage, nextPage);
                else if (navigationMode != NavigationMode.Refresh)
                    await pageAnimation.AnimateForwardNavigatedToAsync(previousPage, nextPage);
            }

            if (nextPage != null)
                nextPage.Opacity = 1;
        }
Beispiel #31
0
 internal static void ExecuteAnimation(IAnimationPage page, UIView animatingView, IPageAnimation animation, bool isPop)
 {
     if (animation.Type == AnimationType.Flip)
     {
         RunUIAnimation(page, animatingView, animation, isPop);
     }
     else
     {
         RunCAAnimation(animatingView, animation, isPop);
     }
 }