Пример #1
0
        private void menuOverlayRenderer_PointerReleased(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            var point = e.GetCurrentPoint(_mainCanvas);

            if (point.PointerId != _pointID)
            {
                return;
            }
            _dragGesture.DragFinished();
            _pointID  = uint.MaxValue;
            e.Handled = true;
        }
Пример #2
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            if (_dragGesture == null)
            {
                return(false);
            }
            MotionEventActions action = e.Action & MotionEventActions.Mask;

            if (action == MotionEventActions.Down)
            {
                _dragGesture.DragBegin(e.RawX, e.RawY);
            }
            if (action == MotionEventActions.Move)
            {
                _dragGesture.DragMoving(e.RawX, e.RawY);
            }
            if (action == MotionEventActions.Up)
            {
                _dragGesture.DragFinished();
            }
            return(true);
        }
        void LayoutMenu()
        {
            if (!CheckPageAndMenu())
            {
                return;
            }

            // areadly add gesture
            if (_dragGesture != null)
            {
                return;
            }

            var menu = _basePage.SlideMenu;

            _dragGesture = DragGestureFactory.GetGestureByView(menu);
            _dragGesture.RequestLayout = (l, t, r, b, density) => {
                _menuOverlayRenderer.NativeView.Frame = new CGRect(l, t, (r - l), (b - t));
                _menuOverlayRenderer.NativeView.SetNeedsLayout();
            };
            _dragGesture.NeedShowBackgroundView = (open, alpha) => {
                UIView.CommitAnimations();
                if (open)
                {
                    ShowBackgroundOverlay(alpha);
                }
                else
                {
                    HideBackgroundOverlay();
                }
            };

            _basePage.HideMenuAction = () => {
                UIView.BeginAnimations("OpenAnimation");
                UIView.SetAnimationDuration(((double)menu.AnimationDurationMillisecond) / 1000);
                _dragGesture.LayoutHideStatus();
            };

            _basePage.ShowMenuAction = () => {
                UIView.BeginAnimations("OpenAnimation");
                UIView.SetAnimationDuration(((double)menu.AnimationDurationMillisecond) / 1000);
                _dragGesture.LayoutShowStatus();
            };

            if (_menuOverlayRenderer == null)
            {
                _menuOverlayRenderer = Platform.CreateRenderer(menu);
                Platform.SetRenderer(menu, _menuOverlayRenderer);

                _panGesture = new UIPanGestureRecognizer(() => {
                    var p0 = _panGesture.LocationInView(_pageRenderer.View);
                    if (_panGesture.State == UIGestureRecognizerState.Began)
                    {
                        _dragGesture.DragBegin(p0.X, p0.Y);
                    }
                    else if (_panGesture.State == UIGestureRecognizerState.Changed &&
                             _panGesture.NumberOfTouches == 1)
                    {
                        _dragGesture.DragMoving(p0.X, p0.Y);
                    }
                    else if (_panGesture.State == UIGestureRecognizerState.Ended)
                    {
                        _dragGesture.DragFinished();
                    }
                });
                _menuOverlayRenderer.NativeView.AddGestureRecognizer(_panGesture);
            }

            var rect = _dragGesture.GetHidePosition();

            menu.Layout(new Rectangle(
                            rect.left,
                            rect.top,
                            (rect.right - rect.left),
                            (rect.bottom - rect.top)));
            _menuOverlayRenderer.NativeView.Hidden = !menu.IsVisible;
            _menuOverlayRenderer.NativeView.Frame  = new CGRect(
                rect.left,
                rect.top,
                (rect.right - rect.left),
                (rect.bottom - rect.top));
            _menuOverlayRenderer.NativeView.SetNeedsLayout();
        }
Пример #4
0
        void LayoutMenu()
        {
            if (!CheckPageAndMenu ())
                return;

            // areadly add gesture
            if (_dragGesture != null)
                return;

            var menu = _basePage.SlideMenu;

            _dragGesture = DragGestureFactory.GetGestureByView (menu);
            _dragGesture.RequestLayout = (l, t, r, b, density) => {
                _menuOverlayRenderer.NativeView.Frame = new CGRect (l, t, (r - l), (b - t));
                _menuOverlayRenderer.NativeView.SetNeedsLayout ();
            };
            _dragGesture.NeedShowBackgroundView = (open, alpha) => {
                UIView.CommitAnimations ();
                if (open)
                    ShowBackgroundOverlay (alpha);
                else
                    HideBackgroundOverlay ();
            };

            _basePage.HideMenuAction = () => {
                UIView.BeginAnimations ("OpenAnimation");
                UIView.SetAnimationDuration (((double)menu.AnimationDurationMillisecond) / 1000);
                _dragGesture.LayoutHideStatus ();

            };

            _basePage.ShowMenuAction = () => {
                UIView.BeginAnimations ("OpenAnimation");
                UIView.SetAnimationDuration (((double)menu.AnimationDurationMillisecond) / 1000);
                _dragGesture.LayoutShowStatus ();
            };

            if (_menuOverlayRenderer == null) {
                _menuOverlayRenderer = RendererFactory.GetRenderer (menu);

                _panGesture = new UIPanGestureRecognizer (() => {
                    var p0 = _panGesture.LocationInView (_pageRenderer.View);
                    if (_panGesture.State == UIGestureRecognizerState.Began) {
                        _dragGesture.DragBegin (p0.X, p0.Y);

                    } else if (_panGesture.State == UIGestureRecognizerState.Changed
                               && _panGesture.NumberOfTouches == 1) {
                        _dragGesture.DragMoving (p0.X, p0.Y);

                    } else if (_panGesture.State == UIGestureRecognizerState.Ended) {
                        _dragGesture.DragFinished ();
                    }
                });
                _menuOverlayRenderer.NativeView.AddGestureRecognizer (_panGesture);
            }

            var rect = _dragGesture.GetHidePosition ();
            menu.Layout (new Xamarin.Forms.Rectangle (
                rect.left,
                rect.top,
                (rect.right - rect.left),
                (rect.bottom - rect.top)));
            _menuOverlayRenderer.NativeView.Hidden = !menu.IsVisible;
            _menuOverlayRenderer.NativeView.Frame = new CGRect (
                rect.left,
                rect.top,
                (rect.right - rect.left),
                (rect.bottom - rect.top));
            _menuOverlayRenderer.NativeView.SetNeedsLayout ();
        }