-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomIVavigation.cs
More file actions
117 lines (98 loc) · 2.92 KB
/
CustomIVavigation.cs
File metadata and controls
117 lines (98 loc) · 2.92 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
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
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
public class CustomNavigation : INavigation
{
private Stack<Page> _navigationStack = new Stack<Page>();
public IReadOnlyList<Page> NavigationStack => _navigationStack.ToArray();
public IReadOnlyList<Page> ModalStack => new List<Page>();
public Task PushAsync(Page page)
{
_navigationStack.Push(page);
// Code pour afficher la page, par exemple :
DisplayPage(page);
return Task.CompletedTask;
}
public Task<Page> PopAsync()
{
if (_navigationStack.Count > 1)
{
var page = _navigationStack.Pop();
// Code pour retirer la page de l'affichage, par exemple :
RemovePage(page);
return Task.FromResult(page);
}
return Task.FromResult<Page>(null);
}
public Task PushModalAsync(Page page)
{
// Implémentation personnalisée pour les modaux si nécessaire
return Task.CompletedTask;
}
public Task<Page> PopModalAsync()
{
// Implémentation personnalisée pour les modaux si nécessaire
return Task.FromResult<Page>(null);
}
public void RemovePage(Page page)
{
var stack = new Stack<Page>(_navigationStack);
var newStack = new Stack<Page>();
while (stack.Count > 0)
{
var p = stack.Pop();
if (p != page)
{
newStack.Push(p);
}
}
_navigationStack = new Stack<Page>(newStack);
}
public void InsertPageBefore(Page page, Page before)
{
var stack = new Stack<Page>(_navigationStack);
var newStack = new Stack<Page>();
while (stack.Count > 0)
{
var p = stack.Pop();
if (p == before)
{
newStack.Push(page);
}
newStack.Push(p);
}
_navigationStack = new Stack<Page>(newStack);
}
private void DisplayPage(Page page)
{
// Code pour afficher la page, par exemple :
Console.WriteLine("Displaying " + page.Title);
}
private void RemovePageFromDisplay(Page page)
{
// Code pour retirer la page de l'affichage, par exemple :
Console.WriteLine("Removing " + page.Title);
}
// Les autres méthodes de INavigation doivent également être implémentées
public Task<Page> PopToRootAsync()
{
// Implémentation de PopToRootAsync
return Task.FromResult<Page>(null);
}
public Task PushAsync(Page page, bool animated)
{
return PushAsync(page);
}
public Task<Page> PopAsync(bool animated)
{
return PopAsync();
}
public Task PushModalAsync(Page page, bool animated)
{
return PushModalAsync(page);
}
public Task<Page> PopModalAsync(bool animated)
{
return PopModalAsync();
}
}