From dba0d47f6dcc755ad5759899322e1a4ebb64e433 Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Mon, 18 Apr 2022 16:39:07 -0500 Subject: [PATCH] Ignore menu code pre iOS13 --- src/Core/src/Handlers/MenuBar/MenuBarHandler.iOS.cs | 3 +++ .../src/Handlers/MenuFlyoutItem/MenuFlyoutItemHandler.iOS.cs | 3 +++ src/Core/src/Handlers/Window/WindowHandler.iOS.cs | 5 ++++- src/Core/src/Platform/iOS/MauiUIApplicationDelegate.Menu.cs | 3 +++ src/Core/src/Platform/iOS/MenuExtensions.cs | 3 +++ 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Core/src/Handlers/MenuBar/MenuBarHandler.iOS.cs b/src/Core/src/Handlers/MenuBar/MenuBarHandler.iOS.cs index a33701c9953d..fc76e5dff7d6 100644 --- a/src/Core/src/Handlers/MenuBar/MenuBarHandler.iOS.cs +++ b/src/Core/src/Handlers/MenuBar/MenuBarHandler.iOS.cs @@ -24,6 +24,9 @@ public override void SetVirtualView(IElement view) void BuildNewMenu() { + if (!OperatingSystem.IsIOSVersionAtLeast(13)) + return; + UIMenu? lastFoundMenu = null; foreach (var item in VirtualView) { diff --git a/src/Core/src/Handlers/MenuFlyoutItem/MenuFlyoutItemHandler.iOS.cs b/src/Core/src/Handlers/MenuFlyoutItem/MenuFlyoutItemHandler.iOS.cs index 3f6048dd5dab..24d2fe181561 100644 --- a/src/Core/src/Handlers/MenuFlyoutItem/MenuFlyoutItemHandler.iOS.cs +++ b/src/Core/src/Handlers/MenuFlyoutItem/MenuFlyoutItemHandler.iOS.cs @@ -52,6 +52,9 @@ internal static void Execute(UICommand uICommand) internal static void Reset() { + if (!OperatingSystem.IsIOSVersionAtLeast(13)) + return; + menus.Clear(); } } diff --git a/src/Core/src/Handlers/Window/WindowHandler.iOS.cs b/src/Core/src/Handlers/Window/WindowHandler.iOS.cs index 2e97f08de633..b46b79749fe6 100644 --- a/src/Core/src/Handlers/Window/WindowHandler.iOS.cs +++ b/src/Core/src/Handlers/Window/WindowHandler.iOS.cs @@ -1,4 +1,4 @@ -using System; +using System; using ObjCRuntime; using UIKit; @@ -22,6 +22,9 @@ public static void MapContent(IWindowHandler handler, IWindow window) public static void MapMenuBar(IWindowHandler handler, IWindow view) { + if (!OperatingSystem.IsIOSVersionAtLeast(13)) + return; + if (MauiUIApplicationDelegate.Current != null && view is IMenuBarElement mb) { diff --git a/src/Core/src/Platform/iOS/MauiUIApplicationDelegate.Menu.cs b/src/Core/src/Platform/iOS/MauiUIApplicationDelegate.Menu.cs index 4ec566c50ba3..fae497cc3466 100644 --- a/src/Core/src/Platform/iOS/MauiUIApplicationDelegate.Menu.cs +++ b/src/Core/src/Platform/iOS/MauiUIApplicationDelegate.Menu.cs @@ -17,6 +17,9 @@ public override void BuildMenu(IUIMenuBuilder builder) base.BuildMenu(builder); + if (!OperatingSystem.IsIOSVersionAtLeast(13)) + return; + MenuBuilder = builder; var window = Window ?? this.GetWindow() ?? diff --git a/src/Core/src/Platform/iOS/MenuExtensions.cs b/src/Core/src/Platform/iOS/MenuExtensions.cs index eab8eb6a5a1b..b9420edfeece 100644 --- a/src/Core/src/Platform/iOS/MenuExtensions.cs +++ b/src/Core/src/Platform/iOS/MenuExtensions.cs @@ -43,6 +43,9 @@ internal static UIMenu ToPlatformMenu( IMauiContext mauiContext, IUIMenuBuilder? uIMenuBuilder) { + if (String.IsNullOrWhiteSpace(title)) + throw new ArgumentNullException(nameof(title), $"{menuElements} requires title text."); + uIMenuBuilder = uIMenuBuilder ?? MauiUIApplicationDelegate.Current.MenuBuilder!;