-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2130 from unoplatform/dev/nr/noreflection
fix: Adding caching for generated route maps
- Loading branch information
Showing
5 changed files
with
83 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
namespace Uno.Extensions.Navigation; | ||
|
||
internal static class RouteInfoExtensions | ||
{ | ||
internal static RouteInfo[] Ancestors(this RouteInfo routeInfo, IRouteResolver resolver) | ||
{ | ||
var routes = new List<RouteInfo>(); | ||
routeInfo.NavigatorAncestors(resolver, routes); | ||
return routes.ToArray(); | ||
} | ||
|
||
private static void NavigatorAncestors(this RouteInfo routeInfo, IRouteResolver resolver, IList<RouteInfo> routes) | ||
{ | ||
routes.Insert(0, routeInfo); | ||
|
||
while (routeInfo?.DependsOnRoute is { } dependee) | ||
{ | ||
routes.Insert(0, dependee); | ||
routeInfo = dependee; | ||
} | ||
|
||
if (routeInfo?.Parent is { } parent) | ||
{ | ||
parent.NavigatorAncestors(resolver, routes); | ||
} | ||
} | ||
|
||
internal static RouteInfo[] Ancestors(this INavigator navigator, IRouteResolver resolver) | ||
{ | ||
var routes = new List<RouteInfo>(); | ||
navigator.NavigatorAncestors(resolver, routes); | ||
return routes.ToArray(); | ||
} | ||
|
||
private static void NavigatorAncestors(this INavigator navigator, IRouteResolver resolver, IList<RouteInfo> routes) | ||
{ | ||
var route = (navigator is IStackNavigator deepNav) ? deepNav.FullRoute : navigator?.Route; | ||
while (!(route?.IsEmpty() ?? true)) | ||
{ | ||
var info = resolver.FindByPath(route.Base); | ||
if (info is not null) | ||
{ | ||
routes.Insert(0, info); | ||
} | ||
route = route.Next(); | ||
} | ||
|
||
if (navigator?.GetParent() is { } parent) | ||
{ | ||
parent.NavigatorAncestors(resolver, routes); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 17 additions & 1 deletion
18
testing/TestHarness/TestHarness.Shared/Ext/Navigation/TabBar/TabBarHomeViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,22 @@ | ||
namespace TestHarness.Ext.Navigation.TabBar; | ||
|
||
public record TabBarHomeViewModel(INavigator Navigator) | ||
public partial class TabBarHomeViewModel : ObservableObject | ||
{ | ||
private RouteResolverDefault routeResolver; | ||
public TabBarHomeViewModel(IServiceProvider services) | ||
{ | ||
routeResolver = services.GetRequiredService<RouteResolverDefault>(); | ||
ImplicitMappingEnabled = routeResolver.ReturnImplicitMapping; | ||
} | ||
|
||
[ObservableProperty] | ||
private bool _implicitMappingEnabled; | ||
|
||
[RelayCommand] | ||
public void ToggleIsChecked() | ||
{ | ||
routeResolver.ReturnImplicitMapping = !routeResolver.ReturnImplicitMapping; | ||
ImplicitMappingEnabled = routeResolver.ReturnImplicitMapping; | ||
} | ||
} | ||
|