diff --git a/src/Controls/src/Core/FlyoutPage.cs b/src/Controls/src/Core/FlyoutPage.cs index 6c9309709cd4..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 = DeviceDisplay.MainDisplayInfo.Orientation; + 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 new file mode 100644 index 000000000000..6b392030e5ab --- /dev/null +++ b/src/Core/src/Platform/Android/WindowExtensions.cs @@ -0,0 +1,24 @@ +using Android.App; +using Android.Content.Res; +using Microsoft.Maui.Devices; +using Microsoft.Maui.Platform; + +namespace Microsoft.Maui +{ + public static partial class WindowExtensions + { + 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 new file mode 100644 index 000000000000..26c476dbde0b --- /dev/null +++ b/src/Core/src/Platform/Standard/WindowExtensions.cs @@ -0,0 +1,10 @@ +using Microsoft.Maui.Devices; + +namespace Microsoft.Maui +{ + public static partial class WindowExtensions + { + 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 b21b0972d523..1bcb11b225c7 100644 --- a/src/Core/src/Platform/Tizen/WindowExtensions.cs +++ b/src/Core/src/Platform/Tizen/WindowExtensions.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Threading.Tasks; using ElmSharp; +using Microsoft.Maui.ApplicationModel; using Tizen.UIExtensions.Common; using Tizen.UIExtensions.ElmSharp; using ELayout = ElmSharp.Layout; @@ -110,5 +111,20 @@ static void OnBackButtonPressed(Window window) s_windowCloseRequestHandler[window].Invoke(); } + 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 + { + 0 => isTV ? Devices.DisplayOrientation.Landscape : Devices.DisplayOrientation.Portrait, + 90 => isTV ? Devices.DisplayOrientation.Portrait : Devices.DisplayOrientation.Landscape, + 180 => isTV ? Devices.DisplayOrientation.Landscape : Devices.DisplayOrientation.Portrait, + 270 => isTV ? Devices.DisplayOrientation.Portrait : Devices.DisplayOrientation.Landscape, + _ => Devices.DisplayOrientation.Unknown + }; + } } } \ No newline at end of file diff --git a/src/Core/src/Platform/Windows/WindowExtensions.cs b/src/Core/src/Platform/Windows/WindowExtensions.cs index ae5acc41ad3b..0ef3605f38ae 100644 --- a/src/Core/src/Platform/Windows/WindowExtensions.cs +++ b/src/Core/src/Platform/Windows/WindowExtensions.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Microsoft.Maui.Media; using WinRT.Interop; +using Windows.Graphics.Display; namespace Microsoft.Maui.Platform { @@ -60,5 +61,28 @@ public static float GetDisplayDensity(this UI.Xaml.Window platformWindow) var windowId = UI.Win32Interop.GetWindowIdFromWindow(hwnd); return UI.Windowing.AppWindow.GetFromWindowId(windowId); } + + 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) + return DisplayOrientation.Unknown; + + DisplayOrientations orientationEnum; + int theScreenWidth = appWindow.Size.Width; + int theScreenHeight = appWindow.Size.Height; + if (theScreenWidth > theScreenHeight) + orientationEnum = DisplayOrientations.Landscape; + else + orientationEnum = DisplayOrientations.Portrait; + + return orientationEnum == DisplayOrientations.Landscape + ? DisplayOrientation.Landscape + : DisplayOrientation.Portrait; + } } } \ No newline at end of file diff --git a/src/Core/src/Platform/iOS/WindowExtensions.cs b/src/Core/src/Platform/iOS/WindowExtensions.cs index 591d6a31556d..8c9a43bcaaef 100644 --- a/src/Core/src/Platform/iOS/WindowExtensions.cs +++ b/src/Core/src/Platform/iOS/WindowExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Text; using System.Threading.Tasks; +using Microsoft.Maui.Devices; using UIKit; namespace Microsoft.Maui.Platform @@ -29,5 +30,8 @@ public static partial class WindowExtensions public static float GetDisplayDensity(this UIWindow uiWindow) => (float)(uiWindow.Screen?.Scale ?? new nfloat(1.0f)); + + internal static DisplayOrientation GetOrientation(this IWindow? window) => + DeviceDisplay.Current.MainDisplayInfo.Orientation; } }