From f70b1be1352747d4b7f0d94bf87bf38bdfc776e3 Mon Sep 17 00:00:00 2001 From: niimima Date: Sun, 14 Jan 2024 17:25:09 +0900 Subject: [PATCH] Modify NavigateFromAsync method --- .../Navigation/PageNavigationService.cs | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs b/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs index f682df7a32..e61137dca7 100644 --- a/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs +++ b/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs @@ -2,6 +2,7 @@ using System.Web; using Prism.Common; using Prism.Events; +using Prism.Extensions; using Prism.Mvvm; using Application = Microsoft.Maui.Controls.Application; using XamlTab = Prism.Navigation.Xaml.TabbedPage; @@ -1333,6 +1334,47 @@ public virtual async Task NavigateFromAsync(string viewName, /// public virtual async Task NavigateFromAsync(string viewName, Uri route, INavigationParameters parameters) { - throw new NotImplementedException(); + await _semaphore.WaitAsync(); + // Ensure adequate time has passed since last navigation so that UI Refresh can Occur + if (DateTime.Now - _lastNavigate < TimeSpan.FromMilliseconds(150)) + { + await Task.Delay(150); + } + + try + { + if (parameters is null) + parameters = new NavigationParameters(); + + NavigationSource = PageNavigationSource.NavigationService; + + var routeSegments = UriParsingHelper.GetUriSegments(route); + + var page = GetPageFromWindow(); + if(page is not null && ViewModelLocator.GetNavigationName(page) == viewName) + { + await ProcessNavigation(page, routeSegments, parameters, null, true); + } + else + { + var viewNameSegment = new Queue(); + viewNameSegment.Enqueue(viewName); + var navigationSegments = new Queue(viewNameSegment.Concat(routeSegments)); + + await ProcessNavigationForAbsoluteUri(routeSegments, parameters, null, true); + } + + return Notify(route, parameters); + } + catch (Exception ex) + { + return Notify(route, parameters, ex); + } + finally + { + _lastNavigate = DateTime.Now; + NavigationSource = PageNavigationSource.Device; + _semaphore.Release(); + } } }