Skip to content
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

Merged
merged 4 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
BackgroundColor="Green"/>
<SwipeItem
Text="Edit"
IconImageSource="calculator.png"
IconImageSource="ic_flag.png"
BackgroundColor="Orange"/>
<SwipeItem
Text="Delete"
Expand Down Expand Up @@ -147,7 +147,7 @@
Mode="Reveal">
<SwipeItem
Text="TopItem"
IconImageSource="coffee.png"
IconImageSource="ic_flag.png"
BackgroundColor="Red"
Invoked="OnInvoked"/>
</SwipeItems>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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();

Copy link
Member

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 ;)

Suggested change

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)
{
Expand All @@ -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>();

Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the source is the same shouldn't right?

Copy link
Member

Choose a reason for hiding this comment

The 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)
Copy link
Member

Choose a reason for hiding this comment

The 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;
Expand Down
7 changes: 7 additions & 0 deletions src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down