-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPageLoader.razor
169 lines (158 loc) · 4.59 KB
/
PageLoader.razor
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
@using Microsoft.Extensions.Logging;
@inject ILogger<PageLoader> Logger;
@code {
public Dictionary<string, string> PageStyles { get; set; } = new();
public Dictionary<string, AppPage> Pages { get; set; } = new();
private AppPage? autoLoadPage;
private string? currentPage;
private string? previousPage;
private string? currentInnerPage;
private string? previousInnerPage;
public void Load(string identifier)
{
Load(identifier, false);
}
public void Load(string identifier, bool inner)
{
if (currentInnerPage != null && !inner)
{
PageStyles[currentInnerPage] = "";
}
string? page = inner ? currentInnerPage : currentPage;
if (page != null)
{
if (Pages[identifier].PreviousAnimationOut != null)
{
if (!Pages[identifier].PreviousAnimationOut.Equals(AnimationType.NONE))
{
PageStyles[page] = "display: block; animation-name: " + Pages[identifier].PreviousAnimationOut;
}
}
else if(Pages[page].AnimationOut != null)
{
PageStyles[page] = "display: block; animation-name: " + Pages[page].AnimationOut;
}
if(!inner)
{
previousPage = currentPage;
} else
{
previousInnerPage = currentInnerPage;
}
}
Logger.LogInformation("Loading page: " + identifier + (inner ? " (Inner page)" : ""));
PageStyles[identifier] = "display: block; animation-name: " + Pages[identifier].AnimationIn;
if(!inner)
{
if (currentInnerPage != null)
{
PageStyles[currentInnerPage] = "";
}
if (previousInnerPage != null)
{
PageStyles[previousInnerPage] = "";
}
currentInnerPage = null;
previousInnerPage = null;
currentPage = identifier;
} else
{
currentInnerPage = identifier;
}
StateHasChanged();
}
public void UnloadLatest()
{
if(currentPage == null || previousPage == null)
{
return;
}
if(Pages[currentPage].AnimationOut != null)
{
PageStyles[currentPage] = "display: block; animation-name: " + Pages[currentPage].AnimationOut;
} else
{
PageStyles[currentPage] = "";
}
string temp = previousPage;
previousPage = currentPage;
currentPage = temp;
StateHasChanged();
}
public void ExitInner()
{
if (currentInnerPage == null)
{
return;
}
if (Pages[currentInnerPage].AnimationOut != null)
{
PageStyles[currentInnerPage] = "display: block; animation-name: " + Pages[currentInnerPage].AnimationOut;
}
currentInnerPage = null;
previousInnerPage = null;
StateHasChanged();
}
public void UnloadLatestInner()
{
if (currentInnerPage == null || previousInnerPage == null)
{
return;
}
if (Pages[currentInnerPage].AnimationOut != null)
{
PageStyles[currentInnerPage] = "display: block; animation-name: " + Pages[currentInnerPage].AnimationOut;
}
else
{
PageStyles[currentInnerPage] = "";
}
string temp = previousInnerPage;
previousInnerPage = currentInnerPage;
currentInnerPage = temp;
PageStyles[currentInnerPage] = "display: block;";
StateHasChanged();
}
public void UnloadAll()
{
foreach (string key in PageStyles.Keys)
{
PageStyles[key] = "";
}
currentInnerPage = null;
previousInnerPage = null;
if (autoLoadPage != null)
{
Load(autoLoadPage.GetType().Name);
} else
{
currentPage = null;
previousPage = null;
}
}
public void RegisterPage(AppPage page)
{
string identifier = page.GetType().Name;
Pages[identifier] = page;
PageStyles[identifier] = "";
if (page.AutoLoad)
{
Load(identifier);
autoLoadPage = page;
}
}
public enum AnimationType
{
SLIDE_TO_RIGHT,
SLIDE_FROM_RIGHT,
SLIDE_TO_LEFT,
SLIDE_FROM_LEFT,
SLIDE_TO_TOP,
SLIDE_FROM_TOP,
SLIDE_TO_BOTTOM,
SLIDE_FROM_BOTTOM,
FADE_IN,
FADE_OUT,
NONE,
}
}