-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
SwipeItemMenuItemHandler.cs
84 lines (69 loc) · 2.71 KB
/
SwipeItemMenuItemHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#if __IOS__ || MACCATALYST
using PlatformView = UIKit.UIButton;
#elif MONOANDROID
using PlatformView = Android.Views.View;
#elif WINDOWS
using PlatformView = Microsoft.UI.Xaml.Controls.SwipeItem;
#elif TIZEN
using PlatformView = Tizen.UIExtensions.NUI.Button;
#elif (NETSTANDARD || !PLATFORM) || (NET6_0_OR_GREATER && !IOS && !ANDROID && !TIZEN)
using PlatformView = System.Object;
#endif
using System.Threading.Tasks;
namespace Microsoft.Maui.Handlers
{
public partial class SwipeItemMenuItemHandler : ISwipeItemMenuItemHandler
{
public static IPropertyMapper<ISwipeItemMenuItem, ISwipeItemMenuItemHandler> Mapper =
new PropertyMapper<ISwipeItemMenuItem, ISwipeItemMenuItemHandler>(ViewHandler.ElementMapper)
{
[nameof(ISwipeItemMenuItem.Visibility)] = MapVisibility,
[nameof(IView.Background)] = MapBackground,
[nameof(IMenuElement.Text)] = MapText,
[nameof(ITextStyle.TextColor)] = MapTextColor,
[nameof(ITextStyle.CharacterSpacing)] = MapCharacterSpacing,
[nameof(ITextStyle.Font)] = MapFont,
[nameof(IMenuElement.Source)] = MapSource,
};
public static CommandMapper<ISwipeItemMenuItem, ISwipeItemMenuItemHandler> CommandMapper =
new(ElementHandler.ElementCommandMapper)
{
};
public SwipeItemMenuItemHandler() : base(Mapper, CommandMapper)
{
}
protected SwipeItemMenuItemHandler(IPropertyMapper? mapper)
: base(mapper ?? Mapper, CommandMapper)
{
}
protected SwipeItemMenuItemHandler(IPropertyMapper? mapper, CommandMapper? commandMapper)
: base(mapper ?? Mapper, commandMapper ?? CommandMapper)
{
}
ISwipeItemMenuItem ISwipeItemMenuItemHandler.VirtualView => VirtualView;
PlatformView ISwipeItemMenuItemHandler.PlatformView => PlatformView;
ImageSourcePartLoader? _imageSourcePartLoader;
public virtual ImageSourcePartLoader SourceLoader =>
_imageSourcePartLoader ??= new ImageSourcePartLoader(new SwipeItemMenuItemImageSourcePartSetter(this));
public static void MapSource(ISwipeItemMenuItemHandler handler, ISwipeItemMenuItem image) =>
MapSourceAsync(handler, image).FireAndForget(handler);
public static Task MapSourceAsync(ISwipeItemMenuItemHandler handler, ISwipeItemMenuItem image)
{
#if WINDOWS
// TODO: make the mapper use the loader and the image if this is a stream source
handler.PlatformView.IconSource = image.Source?.ToIconSource(handler.MauiContext!);
#else
if (handler.SourceLoader is ImageSourcePartLoader loader)
return loader.UpdateImageSourceAsync();
#endif
return Task.CompletedTask;
}
partial class SwipeItemMenuItemImageSourcePartSetter : ImageSourcePartSetter<ISwipeItemMenuItemHandler>
{
public SwipeItemMenuItemImageSourcePartSetter(ISwipeItemMenuItemHandler handler)
: base(handler)
{
}
}
}
}