From e964b47e0ee630db03f1d96257cb2d50069f941e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Sua=CC=81rez?= Date: Tue, 8 Nov 2022 13:37:17 +0100 Subject: [PATCH 1/4] Fix RequestedThemeChanged event on macOS using Shell --- .../Shell/iOS/ShellSectionRootRenderer.cs | 16 +++++++++++++++- .../PublicAPI/net-ios/PublicAPI.Unshipped.txt | 1 + .../net-maccatalyst/PublicAPI.Unshipped.txt | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootRenderer.cs index b78ce2cd9bf0..14c2560389ec 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootRenderer.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel; @@ -129,7 +129,21 @@ public override void ViewSafeAreaInsetsDidChange() LayoutHeader(); } + public override void TraitCollectionDidChange(UITraitCollection previousTraitCollection) + { + base.TraitCollectionDidChange(previousTraitCollection); + + var currentItem = ShellSection.CurrentItem; + + if (!_renderers.ContainsKey(currentItem)) + return; + + var currentItemHandler = _renderers[currentItem]; + var application = currentItemHandler.GetRequiredService(); + application?.ThemeChanged(); + + } void IDisconnectable.Disconnect() { diff --git a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt index bebbb751f7cd..d0c5dd0be9c3 100644 --- a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -93,6 +93,7 @@ virtual Microsoft.Maui.Controls.TappedEventArgs.GetPosition(Microsoft.Maui.Contr ~Microsoft.Maui.Controls.MenuFlyout.Remove(Microsoft.Maui.IMenuElement item) -> bool ~Microsoft.Maui.Controls.MenuFlyout.this[int index].get -> Microsoft.Maui.IMenuElement ~Microsoft.Maui.Controls.MenuFlyout.this[int index].set -> void +~override Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.TraitCollectionDidChange(UIKit.UITraitCollection previousTraitCollection) -> void ~static Microsoft.Maui.Controls.Button.MapContentLayout(Microsoft.Maui.Handlers.IButtonHandler handler, Microsoft.Maui.Controls.Button button) -> void ~static Microsoft.Maui.Controls.Button.MapText(Microsoft.Maui.Handlers.IButtonHandler handler, Microsoft.Maui.Controls.Button button) -> void ~static Microsoft.Maui.Controls.DatePicker.MapUpdateMode(Microsoft.Maui.Handlers.IDatePickerHandler handler, Microsoft.Maui.Controls.DatePicker datePicker) -> void diff --git a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index bebbb751f7cd..d0c5dd0be9c3 100644 --- a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -93,6 +93,7 @@ virtual Microsoft.Maui.Controls.TappedEventArgs.GetPosition(Microsoft.Maui.Contr ~Microsoft.Maui.Controls.MenuFlyout.Remove(Microsoft.Maui.IMenuElement item) -> bool ~Microsoft.Maui.Controls.MenuFlyout.this[int index].get -> Microsoft.Maui.IMenuElement ~Microsoft.Maui.Controls.MenuFlyout.this[int index].set -> void +~override Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.TraitCollectionDidChange(UIKit.UITraitCollection previousTraitCollection) -> void ~static Microsoft.Maui.Controls.Button.MapContentLayout(Microsoft.Maui.Handlers.IButtonHandler handler, Microsoft.Maui.Controls.Button button) -> void ~static Microsoft.Maui.Controls.Button.MapText(Microsoft.Maui.Handlers.IButtonHandler handler, Microsoft.Maui.Controls.Button button) -> void ~static Microsoft.Maui.Controls.DatePicker.MapUpdateMode(Microsoft.Maui.Handlers.IDatePickerHandler handler, Microsoft.Maui.Controls.DatePicker datePicker) -> void From 1da669690a9ca239c9ba15e66a985bc907ab1317 Mon Sep 17 00:00:00 2001 From: Gerald Versluis Date: Fri, 20 Jan 2023 14:06:00 +0100 Subject: [PATCH 2/4] Bad merge fix --- src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt | 2 -- .../src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt index e059cbc655f8..db6c88e48672 100644 --- a/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -4,8 +4,6 @@ ~Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.FrameRenderer(Microsoft.Maui.IPropertyMapper mapper, Microsoft.Maui.CommandMapper commandMapper) -> void override Microsoft.Maui.Controls.View.ChangeVisualState() -> void ~override Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.TraitCollectionDidChange(UIKit.UITraitCollection previousTraitCollection) -> void -~override Microsoft.Maui.Controls.Platform.Compatibility.UIContainerView.AddSubview(UIKit.UIView view) -> void -~override Microsoft.Maui.Controls.Platform.Compatibility.UIContainerView.WillRemoveSubview(UIKit.UIView uiview) -> void virtual Microsoft.Maui.Controls.VisualElement.IsEnabledCore.get -> bool Microsoft.Maui.Controls.VisualElement.RefreshIsEnabledProperty() -> void override Microsoft.Maui.Controls.Button.IsEnabledCore.get -> bool diff --git a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index 59fb6f3d15e1..6922c199a1e7 100644 --- a/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -4,8 +4,6 @@ ~Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.FrameRenderer(Microsoft.Maui.IPropertyMapper mapper, Microsoft.Maui.CommandMapper commandMapper) -> void override Microsoft.Maui.Controls.View.ChangeVisualState() -> void ~override Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.TraitCollectionDidChange(UIKit.UITraitCollection previousTraitCollection) -> void -~override Microsoft.Maui.Controls.Platform.Compatibility.UIContainerView.AddSubview(UIKit.UIView view) -> void -~override Microsoft.Maui.Controls.Platform.Compatibility.UIContainerView.WillRemoveSubview(UIKit.UIView uiview) -> void virtual Microsoft.Maui.Controls.VisualElement.IsEnabledCore.get -> bool Microsoft.Maui.Controls.VisualElement.RefreshIsEnabledProperty() -> void override Microsoft.Maui.Controls.Button.IsEnabledCore.get -> bool From af5121d77d69c0af014736b2492529749e4fe15f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Mon, 20 Feb 2023 14:38:55 +0100 Subject: [PATCH 3/4] Update src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootRenderer.cs Co-authored-by: Manuel de la Pena --- .../Handlers/Shell/iOS/ShellSectionRootRenderer.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootRenderer.cs index 9f1a4ddedb72..f80a57eaa315 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootRenderer.cs @@ -136,11 +136,9 @@ public override void TraitCollectionDidChange(UITraitCollection previousTraitCol var currentItem = ShellSection.CurrentItem; - if (!_renderers.ContainsKey(currentItem)) + if (!_renderers.TryGetValue(currentItem, out var currentItemHandler)) return; - var currentItemHandler = _renderers[currentItem]; - var application = currentItemHandler.GetRequiredService(); application?.ThemeChanged(); From 7df2af368e6a6e9e9cb215c7a8cc4069d2603420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Thu, 16 Mar 2023 14:15:30 +0100 Subject: [PATCH 4/4] Refactoring code --- .../Handlers/Shell/iOS/ShellSectionRootRenderer.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootRenderer.cs index f80a57eaa315..3eee356cd13b 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootRenderer.cs @@ -6,6 +6,7 @@ using CoreAnimation; using CoreGraphics; using Foundation; +using Microsoft.Extensions.DependencyInjection; using ObjCRuntime; using UIKit; @@ -134,14 +135,8 @@ public override void TraitCollectionDidChange(UITraitCollection previousTraitCol { base.TraitCollectionDidChange(previousTraitCollection); - var currentItem = ShellSection.CurrentItem; - - if (!_renderers.TryGetValue(currentItem, out var currentItemHandler)) - return; - - var application = currentItemHandler.GetRequiredService(); + var application = _shellContext?.Shell?.FindMauiContext().Services.GetService(); application?.ThemeChanged(); - } void IDisconnectable.Disconnect()