Exemplo n.º 1
0
        void LayoutSidebar(bool animate)
        {
            if (_gestureActive)
            {
                return;
            }

            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(AnimationDuration);
                UIView.CommitAnimations();
                View.LayoutIfNeeded();
            }

            if (IsOpen && _flyoutBehavior == FlyoutBehavior.Flyout)
            {
                AddTapoffView();
            }
            else
            {
                RemoveTapoffView();
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 3
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();
                }
            }
        }