From 516ba369402226aea6b5c18d2fa4706a59a69884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Sua=CC=81rez?= Date: Tue, 24 Jan 2023 13:29:51 +0100 Subject: [PATCH 1/3] Set the SwipeItem Icon with the correct size after load the SwipeItem (Frame is not empty) --- .../SwipeViewGalleries/BasicSwipeGallery.xaml | 4 +- .../Resources/Images/ic_flag.svg | 1 + .../SwipeItemMenuItemHandler.iOS.cs | 65 ++++++++++++++++--- .../PublicAPI/net-ios/PublicAPI.Unshipped.txt | 2 + .../net-maccatalyst/PublicAPI.Unshipped.txt | 2 + 5 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 src/Controls/samples/Controls.Sample/Resources/Images/ic_flag.svg diff --git a/src/Controls/samples/Controls.Sample/Pages/Controls/SwipeViewGalleries/BasicSwipeGallery.xaml b/src/Controls/samples/Controls.Sample/Pages/Controls/SwipeViewGalleries/BasicSwipeGallery.xaml index f16c2c71ef7c..0be6ffac934e 100644 --- a/src/Controls/samples/Controls.Sample/Pages/Controls/SwipeViewGalleries/BasicSwipeGallery.xaml +++ b/src/Controls/samples/Controls.Sample/Pages/Controls/SwipeViewGalleries/BasicSwipeGallery.xaml @@ -47,7 +47,7 @@ BackgroundColor="Green"/> diff --git a/src/Controls/samples/Controls.Sample/Resources/Images/ic_flag.svg b/src/Controls/samples/Controls.Sample/Resources/Images/ic_flag.svg new file mode 100644 index 000000000000..30421d49eac3 --- /dev/null +++ b/src/Controls/samples/Controls.Sample/Resources/Images/ic_flag.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.iOS.cs b/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.iOS.cs index 0adbf1e836c1..bbe6b55c6601 100644 --- a/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.iOS.cs +++ b/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.iOS.cs @@ -1,34 +1,73 @@ using System; -using System.Collections.Generic; -using System.Text; using CoreGraphics; using Microsoft.Extensions.Logging; -using ObjCRuntime; using UIKit; namespace Microsoft.Maui.Handlers { + internal class SwipeItemButton : UIButton + { + internal event EventHandler? FrameChanged; + + public override CGRect Frame + { + get => base.Frame; + set + { + base.Frame = value; + FrameChanged?.Invoke(this, EventArgs.Empty); + } + } + } + public partial class SwipeItemMenuItemHandler : ElementHandler { protected override UIButton CreatePlatformElement() { - return new UIButton(UIButtonType.Custom) + var swipeItemButton = new SwipeItemButton { RestorationIdentifier = VirtualView.Text, - UserInteractionEnabled = false, + UserInteractionEnabled = false }; + + return swipeItemButton; + } + + protected override void ConnectHandler(UIButton platformView) + { + base.ConnectHandler(platformView); + + if (platformView is SwipeItemButton swipeItemButton) + swipeItemButton.FrameChanged += OnSwipeItemFrameChanged; + } + + protected override void DisconnectHandler(UIButton platformView) + { + base.DisconnectHandler(platformView); + + if (platformView is SwipeItemButton swipeItemButton) + swipeItemButton.FrameChanged -= OnSwipeItemFrameChanged; } public static void MapTextColor(ISwipeItemMenuItemHandler handler, ISwipeItemMenuItem view) { var color = view.GetTextColor(); + if (color != null) handler.PlatformView.SetTitleColor(color.ToPlatform(), UIControlState.Normal); } - public static void MapCharacterSpacing(ISwipeItemMenuItemHandler handler, ITextStyle view) { } + public static void MapCharacterSpacing(ISwipeItemMenuItemHandler handler, ITextStyle view) + { + handler.PlatformView?.UpdateCharacterSpacing(view); + } + + public static void MapFont(ISwipeItemMenuItemHandler handler, ITextStyle view) + { + var fontManager = handler.GetRequiredService(); - public static void MapFont(ISwipeItemMenuItemHandler handler, ITextStyle view) { } + handler.PlatformView?.UpdateFont(view, fontManager); + } public static void MapText(ISwipeItemMenuItemHandler handler, ISwipeItemMenuItem view) { @@ -44,18 +83,26 @@ public static void MapBackground(ISwipeItemMenuItemHandler handler, ISwipeItemMe public static void MapVisibility(ISwipeItemMenuItemHandler handler, ISwipeItemMenuItem view) { var swipeView = handler.PlatformView.GetParentOfType(); + if (swipeView != null) swipeView.UpdateIsVisibleSwipeItem(view); handler.PlatformView.UpdateVisibility(view.Visibility); } + void OnSwipeItemFrameChanged(object? sender, EventArgs e) + { + if (this is ISwipeItemMenuItemHandler swipeItemMenuItemHandler) + swipeItemMenuItemHandler.UpdateValue(nameof(ISwipeItemMenuItem.Source)); + } + void OnSetImageSource(UIImage? image) { + if (PlatformView == null || PlatformView.Frame == CGRect.Empty) + return; + if (image == null) - { PlatformView.SetImage(null, UIControlState.Normal); - } else { var maxWidth = PlatformView.Frame.Width * 0.5f; diff --git a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt index cfe0d72d2cf8..4b35446abf3a 100644 --- a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -1,4 +1,6 @@ #nullable enable +override Microsoft.Maui.Handlers.SwipeItemMenuItemHandler.ConnectHandler(UIKit.UIButton! platformView) -> void +override Microsoft.Maui.Handlers.SwipeItemMenuItemHandler.DisconnectHandler(UIKit.UIButton! platformView) -> void override Microsoft.Maui.Handlers.SwitchHandler.NeedsContainer.get -> bool static Microsoft.Maui.Layouts.LayoutExtensions.ArrangeContentUnbounded(this Microsoft.Maui.IContentView! contentView, Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.Platform.MauiTextField.WillMoveToWindow(UIKit.UIWindow? window) -> void diff --git a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index cfe0d72d2cf8..4b35446abf3a 100644 --- a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -1,4 +1,6 @@ #nullable enable +override Microsoft.Maui.Handlers.SwipeItemMenuItemHandler.ConnectHandler(UIKit.UIButton! platformView) -> void +override Microsoft.Maui.Handlers.SwipeItemMenuItemHandler.DisconnectHandler(UIKit.UIButton! platformView) -> void override Microsoft.Maui.Handlers.SwitchHandler.NeedsContainer.get -> bool static Microsoft.Maui.Layouts.LayoutExtensions.ArrangeContentUnbounded(this Microsoft.Maui.IContentView! contentView, Microsoft.Maui.Graphics.Rect bounds) -> Microsoft.Maui.Graphics.Size override Microsoft.Maui.Platform.MauiTextField.WillMoveToWindow(UIKit.UIWindow? window) -> void From 95bd4ca945b19e7b6c77870cddfad68570e7ec1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Sua=CC=81rez?= Date: Tue, 24 Jan 2023 14:02:04 +0100 Subject: [PATCH 2/3] Added comments --- .../Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.iOS.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.iOS.cs b/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.iOS.cs index bbe6b55c6601..65bf570fd959 100644 --- a/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.iOS.cs +++ b/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.iOS.cs @@ -5,6 +5,7 @@ namespace Microsoft.Maui.Handlers { + // TODO: Make this public on .NET 8 internal class SwipeItemButton : UIButton { internal event EventHandler? FrameChanged; @@ -92,6 +93,7 @@ public static void MapVisibility(ISwipeItemMenuItemHandler handler, ISwipeItemMe void OnSwipeItemFrameChanged(object? sender, EventArgs e) { + // Adjust the size of the icon in case of changing the size of the SwipeItem. if (this is ISwipeItemMenuItemHandler swipeItemMenuItemHandler) swipeItemMenuItemHandler.UpdateValue(nameof(ISwipeItemMenuItem.Source)); } From 9c4fdb0961de3abd1491d31c3e9669544a0b1db6 Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Mon, 30 Jan 2023 17:03:14 +0000 Subject: [PATCH 3/3] Make SwipeItemButton public and add to public api --- .../SwipeItemMenuItem/SwipeItemMenuItemHandler.iOS.cs | 5 ++--- src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt | 5 +++++ .../src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt | 5 +++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.iOS.cs b/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.iOS.cs index 65bf570fd959..e49c2ae9eec5 100644 --- a/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.iOS.cs +++ b/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.iOS.cs @@ -5,10 +5,9 @@ namespace Microsoft.Maui.Handlers { - // TODO: Make this public on .NET 8 - internal class SwipeItemButton : UIButton + public class SwipeItemButton : UIButton { - internal event EventHandler? FrameChanged; + public event EventHandler? FrameChanged; public override CGRect Frame { diff --git a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt index 4b35446abf3a..ca9917266b78 100644 --- a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -1,4 +1,9 @@ #nullable enable +Microsoft.Maui.Handlers.SwipeItemButton +Microsoft.Maui.Handlers.SwipeItemButton.FrameChanged -> System.EventHandler? +Microsoft.Maui.Handlers.SwipeItemButton.SwipeItemButton() -> void +override Microsoft.Maui.Handlers.SwipeItemButton.Frame.get -> CoreGraphics.CGRect +override Microsoft.Maui.Handlers.SwipeItemButton.Frame.set -> void override Microsoft.Maui.Handlers.SwipeItemMenuItemHandler.ConnectHandler(UIKit.UIButton! platformView) -> void override Microsoft.Maui.Handlers.SwipeItemMenuItemHandler.DisconnectHandler(UIKit.UIButton! platformView) -> void override Microsoft.Maui.Handlers.SwitchHandler.NeedsContainer.get -> bool diff --git a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt index 4b35446abf3a..ca9917266b78 100644 --- a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -1,4 +1,9 @@ #nullable enable +Microsoft.Maui.Handlers.SwipeItemButton +Microsoft.Maui.Handlers.SwipeItemButton.FrameChanged -> System.EventHandler? +Microsoft.Maui.Handlers.SwipeItemButton.SwipeItemButton() -> void +override Microsoft.Maui.Handlers.SwipeItemButton.Frame.get -> CoreGraphics.CGRect +override Microsoft.Maui.Handlers.SwipeItemButton.Frame.set -> void override Microsoft.Maui.Handlers.SwipeItemMenuItemHandler.ConnectHandler(UIKit.UIButton! platformView) -> void override Microsoft.Maui.Handlers.SwipeItemMenuItemHandler.DisconnectHandler(UIKit.UIButton! platformView) -> void override Microsoft.Maui.Handlers.SwitchHandler.NeedsContainer.get -> bool