void InitDragGesture() { var menu = Element as SlideCustomDialog; 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 = new VerticalDrawer(menu, this.Resources.DisplayMetrics.Density); _dragGesture.RequestLayout = (l, t, r, b, desity) => { this.SetX((float)l); this.SetY((float)t); }; }
public AnimatorListener(IDialogDrawer dragGesture, bool isShow, IMenuContainerPage basePage) { _dragGesture = dragGesture; _isShow = isShow; _basePage = basePage; }
void LayoutMenu() { if (!CheckPageAndMenu()) { return; } //// areadly add gesture //if (_dialogDrawer != null) //return; var menu = _basePage.SlideMenu; _dialogDrawer = new VerticalDrawer(menu); _dialogDrawer.RequestLayout = (l, t, r, b, density) => { _wrapper.Frame = new CGRect(l, t, (r - l), (b - t)); _wrapper.SetNeedsLayout(); }; _dialogDrawer.NeedShowBackgroundView = (open, alpha) => { if (open) { ShowBackgroundOverlay(alpha); } else { HideBackgroundOverlay(); } }; _basePage.HideMenuAction = () => { UIView.Animate(((double)menu.AnimationDurationMillisecond) / 1000, () => { _dialogDrawer.LayoutHideStatus(); }, () => { _basePage.OnAnimationCompleted(); }); }; _basePage.ShowMenuAction = () => { UIView.Animate(((double)menu.AnimationDurationMillisecond) / 1000, () => { _dialogDrawer.LayoutShowStatus(); }, () => { _basePage.OnAnimationCompleted(); }); }; if (_wrapper != null) { RemoveView(); } _wrapper = new FormsElementWrapper(menu, this.Element); AddView(); var rect = _dialogDrawer.GetHidePosition(); menu.Layout(new Rectangle( rect.left, rect.top, (rect.right - rect.left), (rect.bottom - rect.top))); _wrapper.Frame = new CGRect( rect.left, rect.top, (rect.right - rect.left), (rect.bottom - rect.top)); _wrapper.SetNeedsLayout(); _wrapper.Layer.CornerRadius = (nfloat)_basePage.SlideMenu.CornerRadius; _wrapper.Renderer.NativeView.Layer.CornerRadius = (nfloat)_basePage.SlideMenu.CornerRadius; }
void AddMenu() { if (_basePage == null) { return; } var menu = _basePage.SlideMenu; if (menu == null) { return; } _basePage.HideMenuAction = () => { if (_dialogDrawer == null) { return; } var r = _dialogDrawer.GetHidePosition(); formsWrapper.Animate() .X((float)r.left) .Y((float)r.top) .SetDuration(menu.AnimationDurationMillisecond) .SetListener(new AnimatorListener(_dialogDrawer, false, _basePage)) .Start(); }; _basePage.ShowMenuAction = () => { if (_dialogDrawer == null) { return; } var r = _dialogDrawer.GetShowPosition(); formsWrapper.Animate() .X((float)r.left) .Y((float)r.top) .SetDuration(menu.AnimationDurationMillisecond) .SetListener(new AnimatorListener(_dialogDrawer, true, _basePage)) .Start(); }; if (formsWrapper != null) { formsWrapper.RemoveFromParent(); } formsWrapper = new FormsElementWrapper(Context, menu, this.Element); formsWrapper.SetBackgroundResource(Resource.Drawable.dialogBorder); formsWrapper.Renderer.View.SetBackgroundResource(Resource.Drawable.dialogBorder); var metrics = Resources.DisplayMetrics; var rootView = formsWrapper; _dialogDrawer = (formsWrapper.Renderer as SlideMenuDroidRenderer).GragGesture; if (_dialogDrawer == null) { return; } var rect = _dialogDrawer.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)); rootView.Layout((int)rect.left, (int)rect.top, (int)rect.right, (int)rect.bottom); ViewGroup.AddView(rootView); ViewGroup.BringChildToFront(rootView); _dialogDrawer.NeedShowBackgroundView = (open, alpha) => { if (open) { ShowBackgroundOverlay(alpha); } else { HideBackgroundOverlay(); } }; }