-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
MenuFlyoutHandler.cs
79 lines (65 loc) · 2 KB
/
MenuFlyoutHandler.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
using System;
using System.Collections.Generic;
using System.Text;
#if WINDOWS
using PlatformView = Microsoft.UI.Xaml.Controls.MenuFlyout;
#else
using PlatformView = System.Object;
#endif
namespace Microsoft.Maui.Handlers
{
public partial class MenuFlyoutHandler : IMenuFlyoutHandler
{
public static IPropertyMapper<IMenuFlyout, IMenuFlyoutHandler> Mapper = new PropertyMapper<IMenuFlyout, IMenuFlyoutHandler>(ElementMapper)
{
};
public static CommandMapper<IMenuFlyout, IMenuFlyoutHandler> CommandMapper = new(ElementCommandMapper)
{
[nameof(IMenuFlyoutHandler.Add)] = MapAdd,
[nameof(IMenuFlyoutHandler.Remove)] = MapRemove,
[nameof(IMenuFlyoutHandler.Clear)] = MapClear,
[nameof(IMenuFlyoutHandler.Insert)] = MapInsert,
};
public MenuFlyoutHandler() : this(Mapper, CommandMapper)
{
}
public MenuFlyoutHandler(IPropertyMapper mapper, CommandMapper? commandMapper = null) : base(mapper, commandMapper)
{
}
public static void MapAdd(IMenuFlyoutHandler handler, IMenuFlyout menuElement, object? arg)
{
if (arg is ContextFlyoutItemHandlerUpdate args)
{
handler.Add(args.MenuElement);
}
}
public static void MapRemove(IMenuFlyoutHandler handler, IMenuFlyout menuElement, object? arg)
{
if (arg is ContextFlyoutItemHandlerUpdate args)
{
handler.Remove(args.MenuElement);
}
}
public static void MapInsert(IMenuFlyoutHandler handler, IMenuFlyout menuElement, object? arg)
{
if (arg is ContextFlyoutItemHandlerUpdate args)
{
handler.Insert(args.Index, args.MenuElement);
}
}
public static void MapClear(IMenuFlyoutHandler handler, IMenuFlyout menuElement, object? arg)
{
handler.Clear();
}
IMenuFlyout IMenuFlyoutHandler.VirtualView => VirtualView;
PlatformView IMenuFlyoutHandler.PlatformView => PlatformView;
private protected override void OnDisconnectHandler(object platformView)
{
base.OnDisconnectHandler(platformView);
foreach (var item in VirtualView)
{
item?.Handler?.DisconnectHandler();
}
}
}
}