-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[iOS] Fix issue using SVG in SwipeItem Icon #12882
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -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<ISwipeItemMenuItem, UIButton> | ||||
{ | ||||
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<IFontManager>(); | ||||
|
||||
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<MauiSwipeView>(); | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same :)
Suggested change
|
||||
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)); | ||||
} | ||||
Comment on lines
+93
to
+98
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't this trigger a re-download of the source? Maybe we should be triggering a layout - or requesting some layout again? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the source is the same shouldn't right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jsuarezruiz please we need feedback on this :) |
||||
|
||||
void OnSetImageSource(UIImage? image) | ||||
{ | ||||
if (PlatformView == null || PlatformView.Frame == CGRect.Empty) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is over == |
||||
return; | ||||
|
||||
if (image == null) | ||||
{ | ||||
PlatformView.SetImage(null, UIControlState.Normal); | ||||
} | ||||
else | ||||
{ | ||||
var maxWidth = PlatformView.Frame.Width * 0.5f; | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No noise in a diff please ;)