Skip to content

Commit

Permalink
Refactor insert RemovePageSegment
Browse files Browse the repository at this point in the history
  • Loading branch information
niimima committed Feb 9, 2025
1 parent 193aa59 commit 75ef645
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions src/Maui/Prism.Maui/Navigation/PageNavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ public virtual async Task<INavigationResult> NavigateFromAsync(string viewName,
var foundPage = navigationPages.FirstOrDefault(page => ViewModelLocator.GetNavigationName(page) == viewName);
if (foundPage is null)
{
// Find a page from parents.
var page = currentPage;
while (page != null)
{
Expand All @@ -366,14 +367,19 @@ public virtual async Task<INavigationResult> NavigateFromAsync(string viewName,
}
else
{
// Insert RemovePageSegment.
var removePageCount = navigationPages.IndexOf(foundPage);

// Insert RemovePageSegment.
var routeString = route.ToString();
var tempQueue = new Queue<string>();
for (int i = 0; i < removePageCount; i++)
{
AddToFront(navigationSegments, RemovePageSegment);
tempQueue.Enqueue(RemovePageSegment);
}
while(navigationSegments.Count > 0)
{
tempQueue.Enqueue(navigationSegments.Dequeue());
}
navigationSegments = tempQueue;
}

await ProcessNavigation(currentPage, navigationSegments, parameters, null, null);
Expand All @@ -392,23 +398,6 @@ public virtual async Task<INavigationResult> NavigateFromAsync(string viewName,
}
}

private static void AddToFront<T>(Queue<T> queue, T element)
{
var tempQueue = new Queue<T>();

while (queue.Count > 0)
{
tempQueue.Enqueue(queue.Dequeue());
}

queue.Enqueue(element);

while (tempQueue.Count > 0)
{
queue.Enqueue(tempQueue.Dequeue());
}
}

/// <summary>
/// Selects a Tab of the TabbedPage parent.
/// </summary>
Expand Down

0 comments on commit 75ef645

Please sign in to comment.