-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
ButtonHandler.cs
58 lines (48 loc) · 2.01 KB
/
ButtonHandler.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
#if __IOS__ || MACCATALYST
using PlatformView = UIKit.UIButton;
#elif MONOANDROID
using PlatformView = Google.Android.Material.Button.MaterialButton;
#elif WINDOWS
using PlatformView = Microsoft.UI.Xaml.Controls.Button;
#elif TIZEN
using PlatformView = Tizen.UIExtensions.ElmSharp.Button;
#elif (NETSTANDARD || !PLATFORM) || (NET6_0 && !IOS && !ANDROID && !TIZEN)
using PlatformView = System.Object;
#endif
namespace Microsoft.Maui.Handlers
{
public partial class ButtonHandler : IButtonHandler
{
ImageSourcePartLoader? _imageSourcePartLoader;
public ImageSourcePartLoader ImageSourceLoader =>
_imageSourcePartLoader ??= new ImageSourcePartLoader(this, () => (VirtualView as IImageButton), OnSetImageSource);
public static IPropertyMapper<IImage, IButtonHandler> ImageButtonMapper = new PropertyMapper<IImage, IButtonHandler>()
{
[nameof(IImage.Source)] = MapImageSource
};
public static IPropertyMapper<ITextButton, IButtonHandler> TextButtonMapper = new PropertyMapper<ITextButton, IButtonHandler>()
{
[nameof(ITextStyle.CharacterSpacing)] = MapCharacterSpacing,
[nameof(ITextStyle.Font)] = MapFont,
[nameof(ITextStyle.TextColor)] = MapTextColor,
[nameof(IText.Text)] = MapText
};
public static IPropertyMapper<IButton, IButtonHandler> Mapper = new PropertyMapper<IButton, IButtonHandler>(TextButtonMapper, ImageButtonMapper, ViewHandler.ViewMapper)
{
[nameof(IButton.Background)] = MapBackground,
[nameof(IButton.Padding)] = MapPadding,
[nameof(IButtonStroke.StrokeThickness)] = MapStrokeThickness,
[nameof(IButtonStroke.StrokeColor)] = MapStrokeColor,
[nameof(IButtonStroke.CornerRadius)] = MapCornerRadius
};
public static CommandMapper<IButton, IButtonHandler> CommandMapper = new(ViewCommandMapper);
public ButtonHandler() : base(Mapper, CommandMapper)
{
}
public ButtonHandler(IPropertyMapper? mapper = null) : base(mapper ?? Mapper, CommandMapper)
{
}
IButton IButtonHandler.VirtualView => VirtualView;
PlatformView IButtonHandler.PlatformView => PlatformView;
}
}