diff --git a/src/Controls/src/Core/FlyoutPage.cs b/src/Controls/src/Core/FlyoutPage.cs index a94b7c132c47..01be0205fa72 100644 --- a/src/Controls/src/Core/FlyoutPage.cs +++ b/src/Controls/src/Core/FlyoutPage.cs @@ -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(); diff --git a/src/Controls/tests/Core.UnitTests/FlyoutPageUnitTests.cs b/src/Controls/tests/Core.UnitTests/FlyoutPageUnitTests.cs index a7b564801fd0..2ec58494a521 100644 --- a/src/Controls/tests/Core.UnitTests/FlyoutPageUnitTests.cs +++ b/src/Controls/tests/Core.UnitTests/FlyoutPageUnitTests.cs @@ -281,7 +281,7 @@ public void ThrowsInSetIsPresentOnSplitModeOnTablet() } [Test] - public void ThorwsInSetIsPresentOnSplitPortraitModeOnTablet() + public void ThrowsInSetIsPresentOnSplitPortraitModeOnTablet() { mockDeviceInfo.Idiom = DeviceIdiom.Tablet; mockDeviceDisplay.SetMainDisplayOrientation(DisplayOrientation.Portrait); @@ -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 }; diff --git a/src/Core/src/Platform/Android/WindowExtensions.cs b/src/Core/src/Platform/Android/WindowExtensions.cs index 834f5d48da11..6b392030e5ab 100644 --- a/src/Core/src/Platform/Android/WindowExtensions.cs +++ b/src/Core/src/Platform/Android/WindowExtensions.cs @@ -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 }; + } } } diff --git a/src/Core/src/Platform/Standard/WindowExtensions.cs b/src/Core/src/Platform/Standard/WindowExtensions.cs index 116f02f11c03..26c476dbde0b 100644 --- a/src/Core/src/Platform/Standard/WindowExtensions.cs +++ b/src/Core/src/Platform/Standard/WindowExtensions.cs @@ -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; } } diff --git a/src/Core/src/Platform/Tizen/WindowExtensions.cs b/src/Core/src/Platform/Tizen/WindowExtensions.cs index 4e8e5b86bdd2..1bcb11b225c7 100644 --- a/src/Core/src/Platform/Tizen/WindowExtensions.cs +++ b/src/Core/src/Platform/Tizen/WindowExtensions.cs @@ -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 { diff --git a/src/Core/src/Platform/Windows/WindowExtensions.cs b/src/Core/src/Platform/Windows/WindowExtensions.cs index a8cb4ed1b179..0ef3605f38ae 100644 --- a/src/Core/src/Platform/Windows/WindowExtensions.cs +++ b/src/Core/src/Platform/Windows/WindowExtensions.cs @@ -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) diff --git a/src/Core/src/Platform/iOS/WindowExtensions.cs b/src/Core/src/Platform/iOS/WindowExtensions.cs index ac4ebba24de8..8c9a43bcaaef 100644 --- a/src/Core/src/Platform/iOS/WindowExtensions.cs +++ b/src/Core/src/Platform/iOS/WindowExtensions.cs @@ -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; } }