Skip to content

Commit

Permalink
- fix unit tests and default back to essentials if no window is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen committed May 20, 2022
1 parent f3957aa commit b72f87c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Controls/src/Core/FlyoutPage.cs
Expand Up @@ -166,7 +166,7 @@ bool IFlyoutPageController.ShouldShowSplitMode
return false;

FlyoutLayoutBehavior behavior = FlyoutLayoutBehavior;
var orientation = this.Window?.GetOrientation() ?? DisplayOrientation.Unknown;
var orientation = Window.GetOrientation();

bool isSplitOnLandscape = (behavior == FlyoutLayoutBehavior.SplitOnLandscape || behavior == FlyoutLayoutBehavior.Default) && orientation.IsLandscape();
bool isSplitOnPortrait = behavior == FlyoutLayoutBehavior.SplitOnPortrait && orientation.IsPortrait();
Expand Down
3 changes: 1 addition & 2 deletions src/Controls/tests/Core.UnitTests/FlyoutPageUnitTests.cs
Expand Up @@ -281,7 +281,7 @@ public void ThrowsInSetIsPresentOnSplitModeOnTablet()
}

[Test]
public void ThorwsInSetIsPresentOnSplitPortraitModeOnTablet()
public void ThrowsInSetIsPresentOnSplitPortraitModeOnTablet()
{
mockDeviceInfo.Idiom = DeviceIdiom.Tablet;
mockDeviceDisplay.SetMainDisplayOrientation(DisplayOrientation.Portrait);
Expand All @@ -290,7 +290,6 @@ public void ThorwsInSetIsPresentOnSplitPortraitModeOnTablet()
{
Flyout = new ContentPage { Content = new View(), IsPlatformEnabled = true, Title = "Foo" },
Detail = new ContentPage { Content = new View(), IsPlatformEnabled = true },
IsPlatformEnabled = true,
FlyoutLayoutBehavior = FlyoutLayoutBehavior.SplitOnPortrait
};

Expand Down
9 changes: 7 additions & 2 deletions src/Core/src/Platform/Android/WindowExtensions.cs
Expand Up @@ -7,13 +7,18 @@ namespace Microsoft.Maui
{
public static partial class WindowExtensions
{
internal static DisplayOrientation GetOrientation(this IWindow window) =>
window.Handler?.MauiContext?.GetPlatformWindow()?.Resources?.Configuration?.Orientation switch
internal static DisplayOrientation GetOrientation(this IWindow? window)
{
if (window == null)
return DeviceDisplay.Current.MainDisplayInfo.Orientation;

return window.Handler?.MauiContext?.GetPlatformWindow()?.Resources?.Configuration?.Orientation switch
{
Orientation.Landscape => DisplayOrientation.Landscape,
Orientation.Portrait => DisplayOrientation.Portrait,
Orientation.Square => DisplayOrientation.Portrait,
_ => DisplayOrientation.Unknown
};
}
}
}
4 changes: 2 additions & 2 deletions src/Core/src/Platform/Standard/WindowExtensions.cs
Expand Up @@ -4,7 +4,7 @@ namespace Microsoft.Maui
{
public static partial class WindowExtensions
{
internal static DisplayOrientation GetOrientation(this IWindow window) =>
DisplayOrientation.Unknown;
internal static DisplayOrientation GetOrientation(this IWindow? window) =>
DeviceDisplay.Current.MainDisplayInfo.Orientation;
}
}
5 changes: 4 additions & 1 deletion src/Core/src/Platform/Tizen/WindowExtensions.cs
Expand Up @@ -111,8 +111,11 @@ static void OnBackButtonPressed(Window window)
s_windowCloseRequestHandler[window].Invoke();
}

internal static Devices.DisplayOrientation GetOrientation(this IWindow window)
internal static Devices.DisplayOrientation GetOrientation(this IWindow? window)
{
if (window == null)
return Devices.DeviceDisplay.Current.MainDisplayInfo.Orientation;

bool isTV = Elementary.GetProfile() == "tv";
return window.Handler?.MauiContext?.GetPlatformWindow()?.Rotation switch
{
Expand Down
5 changes: 4 additions & 1 deletion src/Core/src/Platform/Windows/WindowExtensions.cs
Expand Up @@ -62,8 +62,11 @@ public static float GetDisplayDensity(this UI.Xaml.Window platformWindow)
return UI.Windowing.AppWindow.GetFromWindowId(windowId);
}

internal static DisplayOrientation GetOrientation(this IWindow window)
internal static DisplayOrientation GetOrientation(this IWindow? window)
{
if (window == null)
return DeviceDisplay.Current.MainDisplayInfo.Orientation;

var appWindow = window.Handler?.MauiContext?.GetPlatformWindow()?.GetAppWindow();

if (appWindow == null)
Expand Down
8 changes: 2 additions & 6 deletions src/Core/src/Platform/iOS/WindowExtensions.cs
Expand Up @@ -31,11 +31,7 @@ public static partial class WindowExtensions
public static float GetDisplayDensity(this UIWindow uiWindow) =>
(float)(uiWindow.Screen?.Scale ?? new nfloat(1.0f));

#pragma warning disable CA1416 // UIApplication.StatusBarOrientation has [UnsupportedOSPlatform("ios9.0")]. (Deprecated but still works)
internal static DisplayOrientation GetOrientation(this IWindow window) =>
UIApplication.SharedApplication.StatusBarOrientation.IsLandscape()
? DisplayOrientation.Landscape
: DisplayOrientation.Portrait;
#pragma warning restore CA1416
internal static DisplayOrientation GetOrientation(this IWindow? window) =>
DeviceDisplay.Current.MainDisplayInfo.Orientation;
}
}

0 comments on commit b72f87c

Please sign in to comment.