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(); }
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(); }