-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
ImageButtonHandler.cs
74 lines (63 loc) · 2.57 KB
/
ImageButtonHandler.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
#if __IOS__ || MACCATALYST
using PlatformImage = UIKit.UIImage;
using PlatformImageView = UIKit.UIImageView;
using PlatformView = UIKit.UIButton;
#elif MONOANDROID
using PlatformImage = Android.Graphics.Drawables.Drawable;
using PlatformImageView = Android.Widget.ImageView;
using PlatformView = Google.Android.Material.ImageView.ShapeableImageView;
#elif WINDOWS
using System;
using PlatformImage = Microsoft.UI.Xaml.Media.ImageSource;
using PlatformImageView = Microsoft.UI.Xaml.Controls.Image;
using PlatformView = Microsoft.UI.Xaml.Controls.Button;
#elif TIZEN
using PlatformImage = Tizen.UIExtensions.ElmSharp.Image;
using PlatformImageView = Tizen.UIExtensions.ElmSharp.Image;
using PlatformView = Microsoft.Maui.Platform.MauiImageButton;
#elif (NETSTANDARD || !PLATFORM) || (NET6_0 && !IOS && !ANDROID && !TIZEN)
using PlatformImage = System.Object;
using PlatformImageView = System.Object;
using PlatformView = System.Object;
#endif
namespace Microsoft.Maui.Handlers
{
public partial class ImageButtonHandler : IImageButtonHandler
{
public static IPropertyMapper<IImage, IImageHandler> ImageMapper = new PropertyMapper<IImage, IImageHandler>(ImageHandler.Mapper);
public static IPropertyMapper<IImageButton, IImageButtonHandler> Mapper = new PropertyMapper<IImageButton, IImageButtonHandler>(ImageMapper)
{
[nameof(IButtonStroke.StrokeThickness)] = MapStrokeThickness,
[nameof(IButtonStroke.StrokeColor)] = MapStrokeColor,
[nameof(IButtonStroke.CornerRadius)] = MapCornerRadius,
[nameof(IImageButton.Padding)] = MapPadding,
#if WINDOWS
[nameof(IImageButton.Background)] = MapBackground,
#endif
};
public static CommandMapper<IImageButton, IImageButtonHandler> CommandMapper = new(ViewHandler.ViewCommandMapper)
{
};
ImageSourcePartLoader? _imageSourcePartLoader;
public ImageSourcePartLoader SourceLoader =>
_imageSourcePartLoader ??= new ImageSourcePartLoader(this, () => VirtualView, OnSetImageSource);
public ImageButtonHandler() : base(Mapper)
{
}
public ImageButtonHandler(IPropertyMapper mapper) : base(mapper ?? Mapper)
{
}
IImageButton IImageButtonHandler.VirtualView => VirtualView;
IImage IImageHandler.VirtualView => VirtualView;
PlatformImageView IImageHandler.PlatformView =>
#if __IOS__ || TIZEN
PlatformView.ImageView;
#elif WINDOWS
PlatformView.GetContent<PlatformImageView>() ?? throw new InvalidOperationException("ImageButton did not contain an Image element.");
#else
PlatformView;
#endif
PlatformView IImageButtonHandler.PlatformView => PlatformView;
ImageSourcePartLoader IImageHandler.SourceLoader => SourceLoader;
}
}