コード例 #1
0
        void UpdateMenuWithNewSize()
        {
            var menu = _basePage.SlideMenu;

            if (menu != null)
            {
                if (menu.IsFullScreen)
                {
                    if (menu.MenuOrientations == MenuOrientation.BottomToTop ||
                        menu.MenuOrientations == MenuOrientation.TopToBottom)
                    {
                        menu.WidthRequest = ScreenSizeHelper.ScreenWidth;
                    }
                    if (menu.MenuOrientations == MenuOrientation.LeftToRight ||
                        menu.MenuOrientations == MenuOrientation.RightToLeft)
                    {
                        menu.HeightRequest = ScreenSizeHelper.ScreenHeight;
                    }
                }
                if (_dragGesture != null)
                {
                    _dragGesture.UpdateLayoutSize(menu);
                    _dragGesture.LayoutHideStatus();
                }
            }
        }
コード例 #2
0
 public void OnAnimationEnd(Animator animation)
 {
     if (_isShow)
     {
         _dragGesture.LayoutShowStatus();
     }
     else
     {
         _dragGesture.LayoutHideStatus();
     }
 }
コード例 #3
0
        void OnSizeChanged(int w, int h, int oldw, int oldh)
        {
            if (_basePage == null)
            {
                return;
            }

            var metrics = _pageRenderer.Resources.DisplayMetrics;

            ScreenSizeHelper.ScreenWidth  = w / metrics.Density;
            ScreenSizeHelper.ScreenHeight = h / metrics.Density;

            var menu = _basePage.SlideMenu;

            if (menu != null)
            {
                if (_dragGesture != null)
                {
                    _dragGesture.UpdateLayoutSize(menu);

                    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));
                    if (_popMenuOverlayRenderer != null)
                    {
                        _popMenuOverlayRenderer.UpdateLayout();
                    }
                    _dragGesture.LayoutHideStatus();
                    return;
                }
            }

            if (!string.IsNullOrEmpty(_currentPopup))
            {
                LayoutPopup();
            }

            if (_backgroundOverlay != null)
            {
                _backgroundOverlay.Layout(
                    0,
                    0,
                    (int)(ScreenSizeHelper.ScreenWidth * metrics.Density),
                    (int)(ScreenSizeHelper.ScreenHeight * metrics.Density));
            }
        }
コード例 #4
0
        public void ViewWillTransitionToSize(CGSize toSize, IUIViewControllerTransitionCoordinator coordinator)
        {
            var menu = _basePage.SlideMenu;

            // this is used for rotation
            double bigValue   = UIScreen.MainScreen.Bounds.Height > UIScreen.MainScreen.Bounds.Width ? UIScreen.MainScreen.Bounds.Height : UIScreen.MainScreen.Bounds.Width;
            double smallValue = UIScreen.MainScreen.Bounds.Height < UIScreen.MainScreen.Bounds.Width ? UIScreen.MainScreen.Bounds.Height : UIScreen.MainScreen.Bounds.Width;

            if (toSize.Width < toSize.Height)
            {
                ScreenSizeHelper.ScreenHeight = bigValue;
                // this is used for mutiltasking
                ScreenSizeHelper.ScreenWidth = toSize.Width < smallValue ? toSize.Width : smallValue;
            }
            else
            {
                ScreenSizeHelper.ScreenHeight = smallValue;
                ScreenSizeHelper.ScreenWidth  = toSize.Width < bigValue ? toSize.Width : bigValue;
            }

            if (!string.IsNullOrEmpty(_currentPopup))
            {
                GetPopupPositionAndLayout();

                // Layout background
                _backgroundOverlay.Frame = new CGRect(0, 0, ScreenSizeHelper.ScreenWidth, ScreenSizeHelper.ScreenHeight);
            }


            if (_dragGesture == null)
            {
                return;
            }

            _dragGesture.UpdateLayoutSize(menu);
            var rect = _dragGesture.GetHidePosition();

            menu.Layout(new Xamarin.Forms.Rectangle(
                            rect.left,
                            rect.top,
                            (rect.right - rect.left),
                            (rect.bottom - rect.top)));
            _dragGesture.LayoutHideStatus();
        }
コード例 #5
0
        void UpdateMenuLayout()
        {
            var menu = _basePage.SlideMenu;

            if (menu == null || _dragGesture == null)
            {
                return;
            }

            //update layout
            _dragGesture.UpdateLayoutSize(menu);
            var rect = _dragGesture.GetHidePosition();

            menu.Layout(new Xamarin.Forms.Rectangle(
                            rect.left,
                            rect.top,
                            (rect.right - rect.left),
                            (rect.bottom - rect.top)));
            _dragGesture.LayoutHideStatus();
        }
コード例 #6
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 = 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();
        }
コード例 #7
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();
        }
コード例 #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 ();
        }