forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPageRenderer.cs
79 lines (63 loc) · 1.61 KB
/
PageRenderer.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.Collections.ObjectModel;
using Windows.UI.Xaml;
#if WINDOWS_UWP
namespace Xamarin.Forms.Platform.UWP
#else
namespace Xamarin.Forms.Platform.WinRT
#endif
{
public class PageRenderer : VisualElementRenderer<Page, FrameworkElement>
{
bool _disposed;
bool _loaded;
IPageController PageController => Element as IPageController;
protected override void Dispose(bool disposing)
{
if (!disposing || _disposed)
return;
_disposed = true;
if (Element != null)
{
ReadOnlyCollection<Element> children = ((IElementController)Element).LogicalChildren;
for (var i = 0; i < children.Count; i++)
{
var visualChild = children[i] as VisualElement;
visualChild?.Cleanup();
}
PageController?.SendDisappearing();
}
base.Dispose();
}
protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
base.OnElementChanged(e);
((IPageController)e.OldElement)?.SendDisappearing();
if (e.NewElement != null)
{
if (e.OldElement == null)
{
Loaded += OnLoaded;
Unloaded += OnUnloaded;
Tracker = new BackgroundTracker<FrameworkElement>(BackgroundProperty);
}
if (_loaded)
((IPageController)e.NewElement).SendAppearing();
}
}
void OnLoaded(object sender, RoutedEventArgs args)
{
var carouselPage = Element?.Parent as CarouselPage;
if (carouselPage != null && carouselPage.Children[0] != Element)
{
return;
}
_loaded = true;
PageController?.SendAppearing();
}
void OnUnloaded(object sender, RoutedEventArgs args)
{
_loaded = false;
PageController?.SendDisappearing();
}
}
}