forked from dotnet/maui
/
FlyoutPageRenderer.cs
152 lines (131 loc) · 3.8 KB
/
FlyoutPageRenderer.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using System;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Renderers;
namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen
{
public class FlyoutPageRenderer : VisualElementRenderer<FlyoutPage>
{
Native.FlyoutPage _flyoutPage;
FlyoutContainer _flyoutContainer = null;
FlyoutContainer _detailContainer = null;
/// <summary>
/// Default constructor.
/// </summary>
public FlyoutPageRenderer()
{
RegisterPropertyHandler(nameof(Element.Flyout), UpdateFlyout);
RegisterPropertyHandler(nameof(Element.Detail), UpdateDetail);
RegisterPropertyHandler(FlyoutPage.IsPresentedProperty, UpdateIsPresented);
RegisterPropertyHandler(FlyoutPage.FlyoutLayoutBehaviorProperty, UpdateFlyoutLayoutBehavior);
RegisterPropertyHandler(FlyoutPage.IsGestureEnabledProperty, UpdateIsGestureEnabled);
}
protected override void OnElementChanged(ElementChangedEventArgs<FlyoutPage> e)
{
if (_flyoutPage == null)
{
_flyoutPage = new Native.FlyoutPage(Forms.NativeParent)
{
IsPresented = e.NewElement.IsPresented,
Flyout = _flyoutContainer = new FlyoutContainer(Element, true),
Detail = _detailContainer = new FlyoutContainer(Element, false),
};
_flyoutPage.IsPresentedChanged += (sender, ev) =>
{
Element.IsPresented = ev.IsPresent;
};
_flyoutPage.UpdateIsPresentChangeable += (sender, ev) =>
{
(Element as IFlyoutPageController).CanChangeIsPresented = ev.CanChange;
};
SetNativeView(_flyoutPage);
}
if (e.OldElement != null)
{
(e.OldElement as IFlyoutPageController).BackButtonPressed -= OnBackButtonPressed;
e.OldElement.Appearing -= OnFlyoutPageAppearing;
e.OldElement.Disappearing -= OnFlyoutPageDisappearing;
}
if (e.NewElement != null)
{
(e.NewElement as IFlyoutPageController).BackButtonPressed += OnBackButtonPressed;
e.NewElement.Appearing += OnFlyoutPageAppearing;
e.NewElement.Disappearing += OnFlyoutPageDisappearing;
}
UpdateFlyoutLayoutBehavior();
base.OnElementChanged(e);
}
void OnFlyoutPageDisappearing(object sender, EventArgs e)
{
_flyoutContainer?.SendDisappearing();
_detailContainer?.SendDisappearing();
}
void OnFlyoutPageAppearing(object sender, EventArgs e)
{
_flyoutContainer?.SendAppearing();
_detailContainer?.SendAppearing();
}
protected override void OnElementReady()
{
base.OnElementReady();
UpdateFlyout(false);
UpdateDetail(false);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (_flyoutContainer != null)
{
_flyoutContainer.Dispose();
_flyoutContainer = null;
}
if (_detailContainer != null)
{
_detailContainer.Dispose();
_detailContainer = null;
}
if (Element != null)
{
Element.Appearing -= OnFlyoutPageAppearing;
Element.Disappearing -= OnFlyoutPageDisappearing;
}
}
base.Dispose(disposing);
}
protected void UpdateFlyoutRatio(double popoverRatio, double splitRatio)
{
_flyoutPage.PopoverRatio = popoverRatio;
_flyoutPage.SplitRatio = splitRatio;
}
void OnBackButtonPressed(object sender, BackButtonPressedEventArgs e)
{
if ((Element != null) && Element.IsPresented && !_flyoutPage.IsSplit)
{
Element.IsPresented = false;
e.Handled = true;
}
}
void UpdateFlyoutLayoutBehavior()
{
_flyoutPage.FlyoutLayoutBehavior = Element.FlyoutLayoutBehavior;
}
void UpdateFlyout(bool isInit)
{
if (!isInit)
_flyoutContainer.ChildView = Element.Flyout;
}
void UpdateDetail(bool isInit)
{
if (!isInit)
_detailContainer.ChildView = Element.Detail;
}
void UpdateIsPresented()
{
_flyoutPage.IsPresented = Element.IsPresented;
}
void UpdateIsGestureEnabled()
{
_flyoutPage.IsGestureEnabled = Element.IsGestureEnabled;
}
}
}