Skip to content

Commit

Permalink
Modify NavigateFromAsync method
Browse files Browse the repository at this point in the history
  • Loading branch information
niimima committed Jan 14, 2024
1 parent 9622f21 commit f70b1be
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/Maui/Prism.Maui/Navigation/PageNavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1333,6 +1334,47 @@ public virtual async Task<INavigationResult> NavigateFromAsync(string viewName,
/// <inheritdoc />
public virtual async Task<INavigationResult> 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<string>();
viewNameSegment.Enqueue(viewName);
var navigationSegments = new Queue<string>(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();
}
}
}

0 comments on commit f70b1be

Please sign in to comment.