-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
PlatformNavigation.cs
120 lines (98 loc) · 3 KB
/
PlatformNavigation.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
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Xamarin.Forms.Platform.MacOS
{
internal class PlatformNavigation : INavigation, IDisposable
{
ModalPageTracker _modalTracker;
PlatformRenderer _platformRenderer;
bool _animateModals;
bool _disposed;
public PlatformNavigation(PlatformRenderer mainRenderer)
{
_platformRenderer = mainRenderer;
_modalTracker = new ModalPageTracker(_platformRenderer);
_animateModals = true;
}
public ModalPageTracker ModalPageTracker => _modalTracker;
public IReadOnlyList<Page> ModalStack => _modalTracker.ModalStack;
public IReadOnlyList<Page> NavigationStack => new List<Page>();
public bool AnimateModalPages
{
get { return _animateModals; }
set { _animateModals = value; }
}
Task<Page> INavigation.PopAsync()
{
return ((INavigation)this).PopAsync(true);
}
Task<Page> INavigation.PopAsync(bool animated)
{
throw new InvalidOperationException("PopAsync is not supported globally on MacOS, please use a NavigationPage.");
}
Task INavigation.PopToRootAsync()
{
return ((INavigation)this).PopToRootAsync(true);
}
Task INavigation.PopToRootAsync(bool animated)
{
throw new InvalidOperationException("PopToRootAsync is not supported globally on MacOS, please use a NavigationPage.");
}
Task INavigation.PushAsync(Page root)
{
return ((INavigation)this).PushAsync(root, true);
}
Task INavigation.PushAsync(Page root, bool animated)
{
throw new InvalidOperationException("PushAsync is not supported globally on MacOS, please use a NavigationPage.");
}
Task INavigation.PushModalAsync(Page modal)
{
return ((INavigation)this).PushModalAsync(modal, true);
}
Task<Page> INavigation.PopModalAsync()
{
return ((INavigation)this).PopModalAsync(true);
}
Task INavigation.PushModalAsync(Page modal, bool animated)
{
#pragma warning disable CS0618 // Type or member is obsolete
// The Platform property is no longer necessary, but we have to set it because some third-party
// library might still be retrieving it and using it
modal.Platform = _platformRenderer.Platform;
#pragma warning restore CS0618 // Type or member is obsolete
return _modalTracker.PushAsync(modal, _animateModals && animated);
}
Task<Page> INavigation.PopModalAsync(bool animated)
{
return _modalTracker.PopAsync(animated);
}
void INavigation.RemovePage(Page page)
{
throw new InvalidOperationException("RemovePage is not supported globally on macOS, please use a NavigationPage.");
}
void INavigation.InsertPageBefore(Page page, Page before)
{
throw new InvalidOperationException(
"InsertPageBefore is not supported globally on macOS, please use a NavigationPage.");
}
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
_modalTracker.Dispose();
_modalTracker = null;
_platformRenderer = null;
}
_disposed = true;
}
}
public void Dispose()
{
Dispose(true);
}
}
}