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();
        }
        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();
        }
        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();
        }
Example #4
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();
        }
Example #5
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();
                    }
                };
            }
        }
        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 ();
        }