Пример #1
0
        void InitDragGesture()
        {
            var menu = Element as SlideMenuView;

            if (menu == null)
            {
                return;
            }
            if (ScreenSizeHelper.ScreenHeight == 0 && ScreenSizeHelper.ScreenWidth == 0)
            {
                ScreenSizeHelper.ScreenWidth  = Resources.DisplayMetrics.WidthPixels / Resources.DisplayMetrics.Density;
                ScreenSizeHelper.ScreenHeight = Resources.DisplayMetrics.HeightPixels / Resources.DisplayMetrics.Density;
            }
            _dragGesture = DragGestureFactory.GetGestureByView(menu, this.Resources.DisplayMetrics.Density);
            _dragGesture.RequestLayout = (l, t, r, b, desity) => {
                this.SetX((float)l);
                this.SetY((float)t);
            };
        }
        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();
        }
Пример #3
0
        void LayoutMenu()
        {
            if (!CheckPageAndMenu())
            {
                return;
            }
            var menu = _basePage.SlideMenu;

            _dragGesture = DragGestureFactory.GetGestureByView(menu);
            _dragGesture.RequestLayout = (l, t, r, b, density) =>
            {
                menu.Layout(new Xamarin.Forms.Rectangle(
                                l,
                                t,
                                (r - l),
                                (b - t)));
                Canvas.SetLeft(_popMenuOverlayRenderer, l);
                Canvas.SetTop(_popMenuOverlayRenderer, t);
                Canvas.SetZIndex(_popMenuOverlayRenderer, 254);
                _popMenuOverlayRenderer.UpdateLayout();
                _mainCanvas.UpdateLayout();
            };
            _dragGesture.NeedShowBackgroundView = (open, alpha) =>
            {
                if (open)
                {
                    ShowBackgroundOverlay(alpha);
                }
                else
                {
                    HideBackgroundOverlay();
                }
            };

            _basePage.HideMenuAction = () =>
            {
                if (_dragGesture == null)
                {
                    return;
                }
                _dragGesture.LayoutHideStatus();
                // DoubleAnimation wasn't supported by UWP?
                //DoubleAnimation dal = new DoubleAnimation();
                //dal.From = Canvas.GetLeft(_popMenuOverlayRenderer);
                //dal.To = rectp.left;
                //dal.Duration = new Duration(TimeSpan.FromMilliseconds(menu.AnimationDurationMillisecond));
                //DoubleAnimation dat = new DoubleAnimation();
                //dat.From = Canvas.GetTop(_popMenuOverlayRenderer);
                //dat.To = rectp.top;
                //dat.Duration = new Duration(TimeSpan.FromMilliseconds(menu.AnimationDurationMillisecond));
                //(_popMenuOverlayRenderer as UIElement).BeginAnimation(Canvas.LeftProperty, dal);
            };

            _basePage.ShowMenuAction = () =>
            {
                if (_dragGesture == null)
                {
                    return;
                }
                _dragGesture.LayoutShowStatus();
            };
            if (_popMenuOverlayRenderer == null)
            {
                _popMenuOverlayRenderer = Platform.CreateRenderer(menu) as LayoutRenderer;
                _popMenuOverlayRenderer.PointerPressed  += menuOverlayRenderer_PointerPressed;
                _popMenuOverlayRenderer.PointerMoved    += menuOverlayRenderer_PointerMoved;
                _popMenuOverlayRenderer.PointerReleased += menuOverlayRenderer_PointerReleased;
                _popMenuOverlayRenderer.PointerExited   += menuOverlayRenderer_PointerReleased;
            }
            var rect = _dragGesture.GetHidePosition();

            menu.Layout(new Xamarin.Forms.Rectangle(
                            rect.left,
                            rect.top,
                            (rect.right - rect.left),
                            (rect.bottom - rect.top)));
            Canvas.SetLeft(_popMenuOverlayRenderer, rect.left);
            Canvas.SetTop(_popMenuOverlayRenderer, rect.top);
            _popMenuOverlayRenderer.Visibility = menu.IsVisible ? Visibility.Visible : Visibility.Collapsed;
            _popMenuOverlayRenderer.UpdateLayout();
        }
Пример #4
0
        void AddMenu()
        {
            if (_basePage == null)
            {
                return;
            }
            var menu = _basePage.SlideMenu;

            if (menu == null)
            {
                return;
            }

            _basePage.HideMenuAction = () => {
                if (_dragGesture == null)
                {
                    return;
                }
                var rect = _dragGesture.GetHidePosition();
                _popMenuOverlayRenderer.View.Animate()
                .X((float)rect.left)
                .Y((float)rect.top)
                .SetDuration(menu.AnimationDurationMillisecond)
                .SetListener(new AnimatorListener(_dragGesture, false))
                .Start();
            };

            _basePage.ShowMenuAction = () => {
                if (_dragGesture == null)
                {
                    return;
                }
                var rect = _dragGesture.GetShowPosition();
                _popMenuOverlayRenderer.View.Animate()
                .X((float)rect.left)
                .Y((float)rect.top)
                .SetDuration(menu.AnimationDurationMillisecond)
                .SetListener(new AnimatorListener(_dragGesture, true))
                .Start();
            };

            if (_popMenuOverlayRenderer == null)
            {
                menu.Parent             = (Page)_basePage;
                _popMenuOverlayRenderer = Platform.CreateRendererWithContext(menu, _context);
                Platform.SetRenderer(menu, _popupRenderer);

                var metrics  = _pageRenderer.Resources.DisplayMetrics;
                var rootView = _popMenuOverlayRenderer.View;
                if (_popMenuOverlayRenderer is SlideMenuDroidRenderer)
                {
                    _dragGesture = (_popMenuOverlayRenderer as SlideMenuDroidRenderer).GragGesture;
                }
                if (_dragGesture == null)
                {
                    return;
                }
                var rect = _dragGesture.GetHidePosition();

                menu.Layout(new Xamarin.Forms.Rectangle(
                                rect.left / metrics.Density,
                                rect.top / metrics.Density,
                                (rect.right - rect.left) / metrics.Density,
                                (rect.bottom - rect.top) / metrics.Density));

                _popMenuOverlayRenderer.UpdateLayout();
                _popMenuOverlayRenderer.View.Visibility = ViewStates.Visible;
                rootView.Layout((int)rect.left, (int)rect.top, (int)rect.right, (int)rect.bottom);
                _pageRenderer.ViewGroup.AddView(rootView);
                _pageRenderer.ViewGroup.BringChildToFront(rootView);

                _dragGesture.NeedShowBackgroundView = (open, alpha) => {
                    if (open)
                    {
                        ShowBackgroundOverlay(alpha);
                    }
                    else
                    {
                        HideBackgroundOverlay();
                    }
                };
            }
        }
Пример #5
0
 public AnimatorListener(IDragGesture dragGesture, bool isShow)
 {
     _dragGesture = dragGesture;
     _isShow      = isShow;
 }
        void AddMenu()
        {
            if (_basePage == null)
                return;
            var menu = _basePage.SlideMenu;
            if (menu == null)
                return;

            _basePage.HideMenuAction = () => {
                if (_dragGesture == null)
                    return;
                var rect = _dragGesture.GetHidePosition ();
                _popMenuOverlayRenderer.ViewGroup.Animate ()
                    .X ((float)rect.left)
                    .Y ((float)rect.top)
                    .SetDuration (menu.AnimationDurationMillisecond)
                    .SetListener (new AnimatorListener (_dragGesture, false))
                    .Start ();
            };

            _basePage.ShowMenuAction = () => {
                if (_dragGesture == null)
                    return;
                var rect = _dragGesture.GetShowPosition ();
                _popMenuOverlayRenderer.ViewGroup.Animate ()
                    .X ((float)rect.left)
                    .Y ((float)rect.top)
                    .SetDuration (menu.AnimationDurationMillisecond)
                    .SetListener (new AnimatorListener (_dragGesture, true))
                    .Start ();
            };

            if (_popMenuOverlayRenderer == null) {
                _popMenuOverlayRenderer = RendererFactory.GetRenderer (menu);
                var metrics = _pageRenderer.Resources.DisplayMetrics;
                var rootView = _popMenuOverlayRenderer.ViewGroup;
                if (_popMenuOverlayRenderer is SlideMenuDroidRenderer) {
                    _dragGesture = (_popMenuOverlayRenderer as SlideMenuDroidRenderer).GragGesture;
                }
                if (_dragGesture == null)
                    return;
                var rect = _dragGesture.GetHidePosition ();

                menu.Layout (new Xamarin.Forms.Rectangle (
                    rect.left / metrics.Density,
                    rect.top / metrics.Density,
                    (rect.right - rect.left) / metrics.Density,
                    (rect.bottom - rect.top) / metrics.Density));

                _popMenuOverlayRenderer.UpdateLayout ();
                _popMenuOverlayRenderer.ViewGroup.Visibility = ViewStates.Visible;
                rootView.Layout ((int)rect.left, (int)rect.top, (int)rect.right, (int)rect.bottom);
                _pageRenderer.ViewGroup.AddView (rootView);
                _pageRenderer.ViewGroup.BringChildToFront (rootView);

                _dragGesture.NeedShowBackgroundView = (open, alpha) => {
                    if (open)
                        ShowBackgroundOverlay (alpha);
                    else
                        HideBackgroundOverlay ();
                };
            }
        }
 public AnimatorListener(IDragGesture dragGesture, bool isShow)
 {
     _dragGesture = dragGesture;
     _isShow = isShow;
 }
Пример #8
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 ();
        }