Beispiel #1
0
        void IDisconnectable.Disconnect()
        {
            _pageAnimation?.StopAnimation(true);
            _pageAnimation = null;
            if (ShellSection != null)
            {
                ShellSection.PropertyChanged -= OnShellSectionPropertyChanged;
            }

            if (ShellSectionController != null)
            {
                ShellSectionController.ItemsCollectionChanged -= OnShellSectionItemsChanged;
            }

            if (_shellContext?.Shell != null)
            {
                _shellContext.Shell.PropertyChanged -= HandleShellPropertyChanged;
            }

            if (_renderers != null)
            {
                foreach (var renderer in _renderers)
                {
                    var oldRenderer = renderer.Value;
                    var element     = oldRenderer.Element;
                    element?.ClearValue(Platform.RendererProperty);
                    (renderer.Value as IDisconnectable)?.Disconnect();
                }
            }
        }
Beispiel #2
0
        void HandlePanGesture(UIPanGestureRecognizer pan)
        {
            var    translation  = pan.TranslationInView(View).X;
            double openProgress = 0;
            double openLimit    = Flyout.ViewController.View.Frame.Width;

            if (IsOpen)
            {
                openProgress = 1 - (-translation / openLimit);
            }
            else
            {
                openProgress = translation / openLimit;
            }

            openProgress = Math.Min(Math.Max(openProgress, 0.0), 1.0);
            var openPixels = openLimit * openProgress;

            switch (pan.State)
            {
            case UIGestureRecognizerState.Changed:
                _gestureActive = true;

                if (TapoffView == null)
                {
                    AddTapoffView();
                }

                if (_flyoutAnimation != null)
                {
                    TapoffView.Layer.RemoveAllAnimations();
                    _flyoutAnimation?.StopAnimation(true);
                    _flyoutAnimation = null;
                }

                TapoffView.Layer.Opacity = (float)openProgress;

                FlyoutTransition.LayoutViews(View.Bounds, (nfloat)openProgress, Flyout.ViewController.View, Detail.View, _flyoutBehavior);
                break;

            case UIGestureRecognizerState.Ended:
                _gestureActive = false;
                if (IsOpen)
                {
                    if (openProgress < .8)
                    {
                        IsOpen = false;
                    }
                }
                else
                {
                    if (openProgress > 0.2)
                    {
                        IsOpen = true;
                    }
                }
                LayoutSidebar(true);
                break;
            }
        }
        void OnMenuPan(UIPanGestureRecognizer panGestureRecognizer)
        {
            var translationX = panGestureRecognizer.TranslationInView(View).X;
            var menuView     = menuViewController.View;

            switch (panGestureRecognizer.State)
            {
            case UIGestureRecognizerState.Began:
            {
                menuAnimator?.StopAnimation(true);
            }
            break;

            case UIGestureRecognizerState.Changed:
            {
                var potentialNewX     = menuView.Frame.X + translationX;
                var translationFactor = GetMenuTranslationFactor(potentialNewX);
                var newX             = menuView.Frame.X + (translationX * translationFactor);
                var totalXDistance   = UIScreen.MainScreen.Bounds.Width - Constants.MenuRightMargin;
                var percentMaximized = (newX + UIScreen.MainScreen.Bounds.Width) / totalXDistance;

                menuView.Frame = new CGRect
                {
                    Location = new CGPoint
                    {
                        X = newX,
                        Y = menuView.Frame.Y,
                    },
                    Size = menuView.Frame.Size,
                };

                menuViewController.SetPercentMaximized((float)percentMaximized);
                menuBackgroundView.Alpha = percentMaximized;
                panGestureRecognizer.SetTranslation(CGPoint.Empty, View);
            }
            break;

            case UIGestureRecognizerState.Ended:
            {
                var x                        = menuView.Frame.X;
                var velocityX                = panGestureRecognizer.VelocityInView(View).X;
                var totalXDistance           = UIScreen.MainScreen.Bounds.Width - Constants.MenuRightMargin;
                var shouldMaximizeByLocation = (x + UIScreen.MainScreen.Bounds.Width) >= totalXDistance / 3f;

                var shouldMaximizeByVelocity = velocityX > Constants.PulloutVelocityThreshold;
                var shouldMinimizeByVelocity = -velocityX > Constants.PulloutVelocityThreshold;
                var shouldMaximize           = !shouldMinimizeByVelocity && (shouldMaximizeByLocation || shouldMaximizeByVelocity);

                var DEST_X            = shouldMaximize ? -Constants.MenuRightMargin : -UIScreen.MainScreen.Bounds.Width;
                var remainingDistance = Math.Abs(x - DEST_X);

                var initialVelocity = MenuIsExceedingBoundaries(menuView.Frame) ? 0f : (nfloat)Math.Abs(velocityX / remainingDistance);
                AnimateMenu(shouldMaximize ? MenuState.Open : MenuState.Closed, (float)initialVelocity);
            }
            break;
            }
        }
Beispiel #4
0
        public static void Animate(double duration, nfloat delay, CubicBezierCurve curve, Action changes, Action completion = null, CancellationToken?cancellationToken = null)
        {
            var propertyAnimator = new UIViewPropertyAnimator(duration, curve.ToCubicTimingParameters());

            propertyAnimator.AddAnimations(changes, delay);

            if (completion != null)
            {
                propertyAnimator.AddCompletion(_ => completion());
            }

            cancellationToken?.Register(() => propertyAnimator.StopAnimation(true));

            propertyAnimator.StartAnimation();
        }
        void HandlePulloutPan(UIPanGestureRecognizer panGestureRecognizer)
        {
            var translationY = panGestureRecognizer.TranslationInView(View).Y;

            switch (panGestureRecognizer.State)
            {
            case UIGestureRecognizerState.Began:
            {
                pulloutAnimator?.StopAnimation(true);
                mainPulloutView.PulloutBeganDragging(pulloutState);
            }
            break;

            case UIGestureRecognizerState.Changed:
            {
                var potentialNewY     = mainPulloutView.Frame.Y + translationY;
                var translationFactor = GetTranslationFactor(potentialNewY);
                var newY             = mainPulloutView.Frame.Y + (translationY * translationFactor);
                var totalYDistance   = (UIScreen.MainScreen.Bounds.Height - Constants.PulloutBottomMargin) - Constants.PulloutTopMargin;
                var percentMaximized = 1 - ((newY - Constants.PulloutTopMargin) / totalYDistance);

                mainPulloutView.Frame = new CGRect
                {
                    Location = new CGPoint
                    {
                        X = mainPulloutView.Frame.X,
                        Y = newY,
                    },
                    Size = mainPulloutView.Frame.Size,
                };

                mainPulloutView.SetPercentMaximized(percentMaximized);
                pulloutBackgroundView.Alpha = percentMaximized;


                var minimizedTotalDistance = pulloutMinDestY - pulloutNeutralDestY;
                var minimizedDeltaProgress = newY - pulloutNeutralDestY;
                minimizedDeltaProgress = minimizedDeltaProgress < 0 ? 0 : minimizedDeltaProgress;
                var percentMinimized = minimizedDeltaProgress / minimizedTotalDistance;
                percentMinimized = percentMinimized > 1 ? 1 : (percentMinimized < 0 ? 0 : percentMinimized);
                mainPulloutView.SetPercentMinimized(percentMinimized);

                panGestureRecognizer.SetTranslation(CGPoint.Empty, View);
            }
            break;

            case UIGestureRecognizerState.Ended:
            {
                var y         = mainPulloutView.Frame.Y;
                var velocityY = panGestureRecognizer.VelocityInView(View).Y;
                var shouldMaximizeByLocation = y <= pulloutMaxDestY || Math.Abs(y - pulloutMaxDestY) < (pulloutNeutralDestY - pulloutMaxDestY) / 2;
                var shouldMaximizeByVelocity = -velocityY > Constants.PulloutVelocityThreshold;
                var shouldMinimizeByVelocity = velocityY > Constants.PulloutVelocityThreshold;
                var shouldMaximize           = !shouldMinimizeByVelocity && (shouldMaximizeByLocation || shouldMaximizeByVelocity);
                var newPulloutState          = shouldMaximize ? PulloutState.Maximized : (isPulloutInMinMode ? PulloutState.Minimized : PulloutState.Neutral);
                var DEST_Y            = PulloutDestinationYFromState(newPulloutState);
                var remainingDistance = Math.Abs(y - DEST_Y);

                AnimatePullout(newPulloutState, (float)(PulloutIsExceedingBoundaries(mainPulloutView.Frame) ? 0f : (nfloat)Math.Abs(velocityY / remainingDistance)));
            }
            break;
            }
        }
Beispiel #6
0
 void ResetAnimation()
 {
     animator.StopAnimation(true);
     springView.Transform = CGAffineTransform.MakeIdentity();
     AnimateView();
 }
Beispiel #7
0
        void LayoutSidebar(bool animate)
        {
            if (_gestureActive)
            {
                return;
            }

            if (animate && _flyoutAnimation != null)
            {
                return;
            }

            if (!animate && _flyoutAnimation != null)
            {
                _flyoutAnimation.StopAnimation(true);
                _flyoutAnimation = null;
            }

            if (Forms.IsiOS10OrNewer)
            {
                if (IsOpen)
                {
                    UpdateTapoffView();
                }

                if (animate && TapoffView != null)
                {
                    var tapOffViewAnimation = CABasicAnimation.FromKeyPath(@"opacity");
                    tapOffViewAnimation.BeginTime = 0;
                    tapOffViewAnimation.Duration  = AnimationDurationInSeconds;
                    tapOffViewAnimation.SetFrom(NSNumber.FromFloat(TapoffView.Layer.Opacity));
                    tapOffViewAnimation.SetTo(NSNumber.FromFloat(IsOpen ? 1 : 0));
                    tapOffViewAnimation.FillMode            = CAFillMode.Forwards;
                    tapOffViewAnimation.RemovedOnCompletion = false;

                    _flyoutAnimation = new UIViewPropertyAnimator(AnimationDurationInSeconds, UIViewAnimationCurve.EaseOut, () =>
                    {
                        FlyoutTransition.LayoutViews(View.Bounds, IsOpen ? 1 : 0, Flyout.ViewController.View, Detail.View, _flyoutBehavior);

                        if (TapoffView != null)
                        {
                            TapoffView.Layer.AddAnimation(tapOffViewAnimation, "opacity");
                        }
                    });

                    _flyoutAnimation.AddCompletion((p) =>
                    {
                        if (p == UIViewAnimatingPosition.End)
                        {
                            if (TapoffView != null)
                            {
                                TapoffView.Layer.Opacity = IsOpen ? 1 : 0;
                                TapoffView.Layer.RemoveAllAnimations();
                            }

                            UpdateTapoffView();
                            _flyoutAnimation = null;
                        }
                    });

                    _flyoutAnimation.StartAnimation();
                    View.LayoutIfNeeded();
                }
                else if (_flyoutAnimation == null)
                {
                    FlyoutTransition.LayoutViews(View.Bounds, IsOpen ? 1 : 0, Flyout.ViewController.View, Detail.View, _flyoutBehavior);
                    UpdateTapoffView();

                    if (TapoffView != null)
                    {
                        TapoffView.Layer.Opacity = IsOpen ? 1 : 0;
                    }
                }
            }
            else
            {
                if (animate)
                {
                    UIView.BeginAnimations(FlyoutAnimationName);
                }

                FlyoutTransition.LayoutViews(View.Bounds, IsOpen ? 1 : 0, Flyout.ViewController.View, Detail.View, _flyoutBehavior);

                if (animate)
                {
                    UIView.SetAnimationCurve(AnimationCurve);
                    UIView.SetAnimationDuration(AnimationDurationInSeconds);
                    UIView.CommitAnimations();
                    View.LayoutIfNeeded();
                }
                UpdateTapoffView();
            }

            void UpdateTapoffView()
            {
                if (IsOpen && _flyoutBehavior == FlyoutBehavior.Flyout)
                {
                    AddTapoffView();
                }
                else
                {
                    RemoveTapoffView();
                }
            }
        }
Beispiel #8
0
 public static void ForceStopAnimation(this UIViewPropertyAnimator animator)
 {
     // Stop animation without finishing.
     animator.StopAnimation(true);
 }