Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout issue for split view mode on iPad #43

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 62 additions & 33 deletions SlideOverKit.iOS/SlideOverKitiOSHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,54 @@ 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 ();
}

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;
Expand All @@ -288,8 +336,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);
}
Expand All @@ -305,40 +361,13 @@ public void ViewDidDisappear (bool animated)

public void ViewWillTransitionToSize (CGSize toSize, IUIViewControllerTransitionCoordinator coordinator)
{
var menu = _basePage.SlideMenu;

// this is used for rotation
//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;
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 ();
ScreenSizeHelper.ScreenWidth = ScreenSizeHelper.ScreenHeight = bigValue;
UpdateMenuLayout ();

//handle resizing after transition is complete
coordinator.AnimateAlongsideTransition ((obj) => {}, (obj) => OnViewWillTransitionToSize (toSize));
}
}
}
Expand Down