Skip to content

Commit

Permalink
feat: Moving navigation to background thread
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrandolph committed Oct 26, 2022
1 parent cc3ba9a commit e36bb3d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/Uno.Extensions.Navigation.UI/Navigator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected Navigator(
{
if (Logger.IsEnabled(LogLevel.Information)) Logger.LogInformationMessage($"Starting Navigation - Navigator: {this.GetType().Name} Request: {request.Route}");
request = request with { Source = this };
return await Task.Run(() => NavigateAsync(request));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,28 @@ protected override async Task<bool> RegionCanNavigate(Route route, RouteInfo? ro
return path;
}

protected override Task PostNavigateAsync()
protected override async Task PostNavigateAsync()
{
if (Control is not null)
{
foreach (var child in Control.Children.OfType<FrameworkElement>())
await Dispatcher.ExecuteAsync(async cancellation =>
{
if(child == CurrentlyVisibleControl)
foreach (var child in Control.Children.OfType<FrameworkElement>())
{
child.Opacity = 1;
child.Visibility = Visibility.Visible;
}
else
{
child.Opacity = 0;
child.Visibility = Visibility.Collapsed;
if (child == CurrentlyVisibleControl)
{
child.Opacity = 1;
child.Visibility = Visibility.Visible;
}
else
{
child.Opacity = 0;
child.Visibility = Visibility.Collapsed;

}
}
}
});
}

return Task.CompletedTask;
}

private FrameworkElement? FindByPath(string? path)
Expand Down
4 changes: 3 additions & 1 deletion src/Uno.Extensions.Navigation/NavigationRequest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
namespace Uno.Extensions.Navigation;

#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
public record NavigationRequest(object Sender, Route Route, CancellationToken? Cancellation = default, Type? Result = null, INavigator? Source = null)
public record NavigationRequest(object Sender, Route Route, CancellationToken? Cancellation = default, Type? Result = null)
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
{
internal INavigator? Source { get; init; }

public override string ToString() => $"Request [Sender: {Sender.GetType().Name}, Route:{Route}, Result: {Result?.Name ?? "N/A"}]";

internal virtual IResponseNavigator? GetResponseNavigator(IResponseNavigatorFactory responseFactory, INavigator navigator) => default;
Expand Down

0 comments on commit e36bb3d

Please sign in to comment.