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..e49c2ae9eec5 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 { + public class SwipeItemButton : UIButton + { + public 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,27 @@ 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) + { + // 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)); + } + 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 b81f0434c04c..a320aaadecfa 100644 --- a/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt @@ -1,4 +1,11 @@ #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 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 b81f0434c04c..a320aaadecfa 100644 --- a/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt @@ -1,4 +1,11 @@ #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 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