From 28a121aaedfa60acf061d0e6b119cf535568b9fe Mon Sep 17 00:00:00 2001 From: git103 Date: Fri, 25 Aug 2017 13:17:42 -0700 Subject: [PATCH 1/2] Fixed layout issue for split screen mode on iPad --- SlideOverKit.iOS/SlideOverKitiOSHandler.cs | 84 ++++++++++++++-------- 1 file changed, 53 insertions(+), 31 deletions(-) diff --git a/SlideOverKit.iOS/SlideOverKitiOSHandler.cs b/SlideOverKit.iOS/SlideOverKitiOSHandler.cs index 73ddd6e..569d092 100644 --- a/SlideOverKit.iOS/SlideOverKitiOSHandler.cs +++ b/SlideOverKit.iOS/SlideOverKitiOSHandler.cs @@ -268,6 +268,24 @@ CGRect GetPopupPositionAndLayout () } + 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 (); + } + public void OnElementChanged (VisualElementChangedEventArgs e) { _basePage = e.NewElement as IMenuContainerPage; @@ -289,8 +307,16 @@ public void ViewDidAppear (bool animated) { if (!CheckPageAndMenu ()) return; - if (_basePage.SlideMenu.IsFullScreen) + if (_basePage.SlideMenu.IsFullScreen) { + + //set screen width + var width = UIApplication.SharedApplication.KeyWindow.Bounds.Width; + ScreenSizeHelper.ScreenWidth = width; + + UpdateMenuLayout (); + UIApplication.SharedApplication.KeyWindow.AddSubview (_menuOverlayRenderer.NativeView); + } else _pageRenderer.View.AddSubview (_menuOverlayRenderer.NativeView); } @@ -306,40 +332,36 @@ public void ViewDidDisappear (bool animated) 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); - } + //handle resizing after transition is complete + coordinator.AnimateAlongsideTransition ((obj) => {}, (obj) => { + + // this is used for rotation + var orientation = UIApplication.SharedApplication.StatusBarOrientation; + 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 (orientation == UIInterfaceOrientation.Portrait || orientation == UIInterfaceOrientation.PortraitUpsideDown) { + ScreenSizeHelper.ScreenHeight = bigValue; + } else { + ScreenSizeHelper.ScreenHeight = smallValue; + } + if (toSize.Width < toSize.Height) { + // this is used for mutiltasking + ScreenSizeHelper.ScreenWidth = toSize.Width < smallValue ? toSize.Width : smallValue; + } else { + ScreenSizeHelper.ScreenWidth = toSize.Width < bigValue ? toSize.Width : bigValue; + } - if (_dragGesture == null) - return; + if (!string.IsNullOrEmpty (_currentPopup)) { + GetPopupPositionAndLayout (); - _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 (); + // Layout background + _backgroundOverlay.Frame = new CGRect (0, 0, ScreenSizeHelper.ScreenWidth, ScreenSizeHelper.ScreenHeight); + } + UpdateMenuLayout (); + }); } } } From 52ccc5daa42f32fcdf2a15a401c920d2bf41f277 Mon Sep 17 00:00:00 2001 From: git103 Date: Fri, 25 Aug 2017 14:58:01 -0700 Subject: [PATCH 2/2] Additional fix for split screen mode on iPad --- SlideOverKit.iOS/SlideOverKitiOSHandler.cs | 65 ++++++++++++---------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/SlideOverKit.iOS/SlideOverKitiOSHandler.cs b/SlideOverKit.iOS/SlideOverKitiOSHandler.cs index 569d092..ac5e22b 100644 --- a/SlideOverKit.iOS/SlideOverKitiOSHandler.cs +++ b/SlideOverKit.iOS/SlideOverKitiOSHandler.cs @@ -286,6 +286,36 @@ void UpdateMenuLayout () _dragGesture.LayoutHideStatus (); } + void OnViewWillTransitionToSize(CGSize toSize) + { + // this is used for rotation + var orientation = UIApplication.SharedApplication.StatusBarOrientation; + 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 (orientation == UIInterfaceOrientation.Portrait || orientation == UIInterfaceOrientation.PortraitUpsideDown) { + ScreenSizeHelper.ScreenHeight = bigValue; + } else { + ScreenSizeHelper.ScreenHeight = smallValue; + } + + if (toSize.Width < toSize.Height) { + // this is used for mutiltasking + ScreenSizeHelper.ScreenWidth = toSize.Width < smallValue ? toSize.Width : smallValue; + } else { + 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); + } + + UpdateMenuLayout (); + } + public void OnElementChanged (VisualElementChangedEventArgs e) { _basePage = e.NewElement as IMenuContainerPage; @@ -332,36 +362,13 @@ public void ViewDidDisappear (bool animated) public void ViewWillTransitionToSize (CGSize toSize, IUIViewControllerTransitionCoordinator coordinator) { - //handle resizing after transition is complete - coordinator.AnimateAlongsideTransition ((obj) => {}, (obj) => { - - // this is used for rotation - var orientation = UIApplication.SharedApplication.StatusBarOrientation; - 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 (orientation == UIInterfaceOrientation.Portrait || orientation == UIInterfaceOrientation.PortraitUpsideDown) { - ScreenSizeHelper.ScreenHeight = bigValue; - } else { - ScreenSizeHelper.ScreenHeight = smallValue; - } - - if (toSize.Width < toSize.Height) { - // this is used for mutiltasking - ScreenSizeHelper.ScreenWidth = toSize.Width < smallValue ? toSize.Width : smallValue; - } else { - ScreenSizeHelper.ScreenWidth = toSize.Width < bigValue ? toSize.Width : bigValue; - } + //initial call to move menu off screen to hide it while transitioning + double bigValue = UIScreen.MainScreen.Bounds.Height > UIScreen.MainScreen.Bounds.Width ? UIScreen.MainScreen.Bounds.Height : UIScreen.MainScreen.Bounds.Width; + ScreenSizeHelper.ScreenWidth = ScreenSizeHelper.ScreenHeight = bigValue; + UpdateMenuLayout (); - if (!string.IsNullOrEmpty (_currentPopup)) { - GetPopupPositionAndLayout (); - - // Layout background - _backgroundOverlay.Frame = new CGRect (0, 0, ScreenSizeHelper.ScreenWidth, ScreenSizeHelper.ScreenHeight); - } - - UpdateMenuLayout (); - }); + //handle resizing after transition is complete + coordinator.AnimateAlongsideTransition ((obj) => {}, (obj) => OnViewWillTransitionToSize (toSize)); } } }