-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathViewHandlerOfT.cs
More file actions
81 lines (65 loc) · 2.41 KB
/
ViewHandlerOfT.cs
File metadata and controls
81 lines (65 loc) · 2.41 KB
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
using System;
#if IOS || MACCATALYST
using PlatformView = UIKit.UIView;
#elif MONOANDROID
using PlatformView = Android.Views.View;
#elif WINDOWS
using PlatformView = Microsoft.UI.Xaml.FrameworkElement;
#elif TIZEN
using PlatformView = Tizen.NUI.BaseComponents.View;
#elif (NETSTANDARD || !PLATFORM) || (NET6_0_OR_GREATER && !IOS && !ANDROID && !TIZEN)
using PlatformView = System.Object;
#endif
namespace Microsoft.Maui.Handlers
{
public abstract partial class ViewHandler<TVirtualView, TPlatformView> : ViewHandler, IViewHandler
where TVirtualView : class, IView
#if !(NETSTANDARD || !PLATFORM) || IOS || ANDROID || WINDOWS || TIZEN
where TPlatformView : PlatformView
#else
where TPlatformView : class
#endif
{
[HotReload.OnHotReload]
internal static void OnHotReload()
{
}
protected ViewHandler(IPropertyMapper mapper, CommandMapper? commandMapper = null)
: base(mapper, commandMapper)
{
}
public new TPlatformView PlatformView
{
get => (TPlatformView?)base.PlatformView ?? throw new InvalidOperationException($"PlatformView cannot be null here");
private protected set => base.PlatformView = value;
}
public new TVirtualView VirtualView
{
get => (TVirtualView?)base.VirtualView ?? throw new InvalidOperationException($"VirtualView cannot be null here");
private protected set => base.VirtualView = value;
}
IView? IViewHandler.VirtualView => base.VirtualView;
IElement? IElementHandler.VirtualView => base.VirtualView;
object? IElementHandler.PlatformView => base.PlatformView;
public virtual void SetVirtualView(IView view) =>
base.SetVirtualView(view);
public sealed override void SetVirtualView(IElement view) =>
SetVirtualView((IView)view);
public static Func<ViewHandler<TVirtualView, TPlatformView>, TPlatformView>? PlatformViewFactory { get; set; }
protected abstract TPlatformView CreatePlatformView();
protected virtual void ConnectHandler(TPlatformView platformView)
{
}
protected virtual void DisconnectHandler(TPlatformView platformView)
{
}
private protected override PlatformView OnCreatePlatformView()
{
return PlatformViewFactory?.Invoke(this) ?? CreatePlatformView();
}
private protected override void OnConnectHandler(PlatformView platformView) =>
ConnectHandler((TPlatformView)platformView);
private protected override void OnDisconnectHandler(PlatformView platformView) =>
DisconnectHandler((TPlatformView)platformView);
}
}