Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
[Windows] Fix modal pages being laid out below soft buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmgarrido committed Sep 29, 2016
1 parent bd195ff commit 617b337
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 38 deletions.
12 changes: 0 additions & 12 deletions Xamarin.Forms.Platform.WinRT.Phone/WindowsPhonePlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@ public WindowsPhonePlatform (Windows.UI.Xaml.Controls.Page page)
_status.Hiding += OnStatusBarHiding;
}

internal override Rectangle WindowBounds
{
get
{
bool landscape = Device.Info.CurrentOrientation.IsLandscape ();
double offset = (landscape) ? _status.OccludedRect.Width : _status.OccludedRect.Height;

Rectangle original = base.WindowBounds;
return new Rectangle (original.X, original.Y, original.Width - ((landscape) ? offset : 0), original.Height - ((landscape) ? 0 : offset));
}
}

This comment has been minimized.

Copy link
@jimmgarrido

jimmgarrido Sep 29, 2016

Author Contributor

We no longer need to manually calculate the area the status bar is occluding since the bounds for Page.Content already factors that in.

readonly StatusBar _status;

void OnStatusBarHiding (StatusBar sender, object args)
Expand Down
31 changes: 5 additions & 26 deletions Xamarin.Forms.Platform.WinRT/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ SizeRequest IPlatform.GetNativeSize(VisualElement element, double widthConstrain
return new SizeRequest();
}

internal virtual Rectangle WindowBounds
internal virtual Rectangle ContainerBounds

This comment has been minimized.

Copy link
@jimmgarrido

jimmgarrido Sep 29, 2016

Author Contributor

Changed the property's name to better reflect its purpose. It was only being referenced in a couple of places so I thought it would be better to utilize the existing one instead of making a new one or using new Rectangle(0, 0, _container.ActualWidth, _container.ActualHeight) in several locations.

{
get { return _bounds; }
}

internal void UpdatePageSizes()
{
Rectangle bounds = WindowBounds;
Rectangle bounds = ContainerBounds;
if (bounds.IsEmpty)
return;
foreach (Page root in _navModel.Roots)
Expand Down Expand Up @@ -420,28 +420,7 @@ void CancelActionSheet()

void UpdateBounds()
{
_bounds = new Rectangle(0, 0, _page.ActualWidth, _page.ActualHeight);
#if WINDOWS_UWP
if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
{
StatusBar statusBar = StatusBar.GetForCurrentView();

bool landscape = Device.Info.CurrentOrientation.IsLandscape();
bool titleBar = CoreApplication.GetCurrentView().TitleBar.IsVisible;
double offset = landscape ? statusBar.OccludedRect.Width : statusBar.OccludedRect.Height;

_bounds = new Rectangle(0, 0, _page.ActualWidth - (landscape ? offset : 0), _page.ActualHeight - (landscape ? 0 : offset));

// Even if the MainPage is a ContentPage not inside of a NavigationPage, the calculated bounds
// assume the TitleBar is there even if it isn't visible. When UpdatePageSizes is called,
// _container.ActualWidth is correct because it's aware that the TitleBar isn't there, but the
// bounds aren't, and things can subsequently run under the StatusBar.
if (!titleBar)
{
_bounds.Width -= (_bounds.Width - _container.ActualWidth);
}
}
#endif
_bounds = new Rectangle(0, 0, _container.ActualWidth, _container.ActualHeight);
}

void OnRendererSizeChanged(object sender, SizeChangedEventArgs sizeChangedEventArgs)
Expand All @@ -467,7 +446,7 @@ async void SetCurrent(Page newPage, bool animated, bool popping = false, Action
previousPage.Cleanup();
}

newPage.Layout(new Rectangle(0, 0, _page.ActualWidth, _page.ActualHeight));
newPage.Layout(ContainerBounds);

IVisualElementRenderer pageRenderer = newPage.GetOrCreateRenderer();
_container.Children.Add(pageRenderer.ContainerElement);
Expand Down Expand Up @@ -712,7 +691,7 @@ void OnPageActionSheet(Page sender, ActionSheetArguments options)

if (Device.Idiom == TargetIdiom.Phone)
{
double height = WindowBounds.Height;
double height = _page.ActualHeight;

This comment has been minimized.

Copy link
@jimmgarrido

jimmgarrido Sep 29, 2016

Author Contributor

ActionSheets on WinRT seemed to be the only thing affected negatively by using the new bounds, so I changed it to use the previous bounds from _page.

stack.Height = height;
stack.Width = size.Width;
border.BorderThickness = new Windows.UI.Xaml.Thickness(0);
Expand Down

0 comments on commit 617b337

Please sign in to comment.