-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement NavigateFromAsync method without recreating a page. #3182
base: master
Are you sure you want to change the base?
Changes from all commits
6ee0fa4
86b68a5
41b3270
e1a4cf5
b1dcfc2
5af4754
a33db2f
7f8a12f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -333,6 +333,71 @@ | |||||||
} | ||||||||
} | ||||||||
|
||||||||
/// <inheritdoc /> | ||||||||
public virtual async Task<INavigationResult> NavigateFromAsync(string viewName, Uri route, INavigationParameters parameters) | ||||||||
{ | ||||||||
await WaitForPendingNavigationRequests(); | ||||||||
|
||||||||
try | ||||||||
{ | ||||||||
if (route.IsAbsoluteUri) throw new NavigationException(NavigationException.UnsupportedAbsoluteUri); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
parameters ??= new NavigationParameters(); | ||||||||
|
||||||||
NavigationSource = PageNavigationSource.NavigationService; | ||||||||
|
||||||||
var navigationSegments = UriParsingHelper.GetUriSegments(route); | ||||||||
|
||||||||
// Find a page that matches the viewName. | ||||||||
var currentPage = GetCurrentPage(); | ||||||||
var navigationPages = currentPage.Navigation.NavigationStack.ToList(); | ||||||||
navigationPages.Reverse(); | ||||||||
var foundPage = navigationPages.FirstOrDefault(page => ViewModelLocator.GetNavigationName(page) == viewName); | ||||||||
if (foundPage is null) | ||||||||
{ | ||||||||
// Find a page from parents. | ||||||||
var page = currentPage; | ||||||||
while (page != null) | ||||||||
{ | ||||||||
if (page is not null && ViewModelLocator.GetNavigationName(page) == viewName) | ||||||||
break; | ||||||||
Check failure on line 363 in src/Maui/Prism.Maui/Navigation/PageNavigationService.cs GitHub Actions / build-prism-maui / Build Prism.Maui
Check failure on line 363 in src/Maui/Prism.Maui/Navigation/PageNavigationService.cs GitHub Actions / build-prism-maui / Build Prism.Maui
Check failure on line 363 in src/Maui/Prism.Maui/Navigation/PageNavigationService.cs GitHub Actions / build-prism-maui / Build Prism.Maui
Check failure on line 363 in src/Maui/Prism.Maui/Navigation/PageNavigationService.cs GitHub Actions / build-prism-maui / Build Prism.Maui
Check failure on line 363 in src/Maui/Prism.Maui/Navigation/PageNavigationService.cs GitHub Actions / build-prism-maui / Build Prism.Maui
Check failure on line 363 in src/Maui/Prism.Maui/Navigation/PageNavigationService.cs GitHub Actions / build-prism-maui / Build Prism.Maui
Check failure on line 363 in src/Maui/Prism.Maui/Navigation/PageNavigationService.cs GitHub Actions / build-prism-maui / Build Prism.Maui
Check failure on line 363 in src/Maui/Prism.Maui/Navigation/PageNavigationService.cs GitHub Actions / build-prism-maui / Build Prism.Maui
|
||||||||
page = page.GetParentPage(); | ||||||||
} | ||||||||
currentPage = page; | ||||||||
} | ||||||||
else | ||||||||
{ | ||||||||
// Insert RemovePageSegment. | ||||||||
var removePageCount = navigationPages.IndexOf(foundPage); | ||||||||
|
||||||||
var tempQueue = new Queue<string>(); | ||||||||
for (int i = 0; i < removePageCount; i++) | ||||||||
{ | ||||||||
tempQueue.Enqueue(RemovePageSegment); | ||||||||
} | ||||||||
while(navigationSegments.Count > 0) | ||||||||
{ | ||||||||
tempQueue.Enqueue(navigationSegments.Dequeue()); | ||||||||
} | ||||||||
navigationSegments = tempQueue; | ||||||||
} | ||||||||
|
||||||||
await ProcessNavigation(currentPage, navigationSegments, parameters, null, null); | ||||||||
|
||||||||
return Notify(route, parameters); | ||||||||
} | ||||||||
catch (Exception ex) | ||||||||
{ | ||||||||
return Notify(route, parameters, ex); | ||||||||
} | ||||||||
finally | ||||||||
{ | ||||||||
_lastNavigate = DateTime.Now; | ||||||||
NavigationSource = PageNavigationSource.Device; | ||||||||
_semaphore.Release(); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
/// <summary> | ||||||||
/// Selects a Tab of the TabbedPage parent. | ||||||||
/// </summary> | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -72,6 +72,11 @@ public class NavigationException : Exception | |||||
/// </summary> | ||||||
public const string UnknownException = "An unknown error occurred. You may need to specify whether to Use Modal Navigation or not."; | ||||||
|
||||||
/// <summary> | ||||||
/// The <see cref="NavigationException"/> Message returned when an absolute path is specified but not supported. | ||||||
/// </summary> | ||||||
public const string UnsupportedAbsoluteUri = "An unsupported absolute uri. Please use a relative URI."; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
/// <summary> | ||||||
/// Initializes a new instance of the <see cref="NavigationException"/> | ||||||
/// </summary> | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would need some overloads that take a string for the route as well.