diff --git a/src/Uno.Extensions.Navigation.UI/RouteInfoExtensions.cs b/src/Uno.Extensions.Navigation.UI/RouteInfoExtensions.cs new file mode 100644 index 0000000000..45c92f99a6 --- /dev/null +++ b/src/Uno.Extensions.Navigation.UI/RouteInfoExtensions.cs @@ -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.NavigatorAncestors(resolver, routes); + return routes.ToArray(); + } + + private static void NavigatorAncestors(this RouteInfo routeInfo, IRouteResolver resolver, IList 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(); + navigator.NavigatorAncestors(resolver, routes); + return routes.ToArray(); + } + + private static void NavigatorAncestors(this INavigator navigator, IRouteResolver resolver, IList 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); + } + } +} diff --git a/src/Uno.Extensions.Navigation.UI/RouteResolver.cs b/src/Uno.Extensions.Navigation.UI/RouteResolver.cs index a7aea99c61..e5b37c5f48 100644 --- a/src/Uno.Extensions.Navigation.UI/RouteResolver.cs +++ b/src/Uno.Extensions.Navigation.UI/RouteResolver.cs @@ -136,7 +136,7 @@ protected static bool IsDialogViewType(Type? viewType = null) { if (viewType is null) { - return false; ; + return false; } return viewType == typeof(MessageDialog) || @@ -147,9 +147,7 @@ protected static bool IsDialogViewType(Type? viewType = null) } public RouteInfo? FindByPath(string? path) - { - return InternalFindByPath(path); - } + => InternalFindByPath(path); protected virtual RouteInfo? InternalFindByPath(string? path) { @@ -175,7 +173,8 @@ protected static bool IsDialogViewType(Type? viewType = null) { return default; } - else if (maps.Length == 1 || + + if (maps.Length == 1 || navigator is null) { return maps[0]; @@ -205,9 +204,7 @@ protected static bool IsDialogViewType(Type? viewType = null) } protected virtual RouteInfo[] InternalFindByViewModel(Type? viewModelType) - { - return FindRouteByType(viewModelType, map => map.ViewModel); - } + => FindRouteByType(viewModelType, map => map.ViewModel); public RouteInfo? FindByView(Type? viewType, INavigator? navigator) { @@ -216,9 +213,7 @@ protected virtual RouteInfo[] InternalFindByViewModel(Type? viewModelType) } protected virtual RouteInfo[] InternalFindByView(Type? viewType) - { - return FindRouteByType(viewType, map => map.RenderView); - } + => FindRouteByType(viewType, map => map.RenderView); public RouteInfo? FindByData(Type? dataType, INavigator? navigator) { @@ -243,65 +238,8 @@ public void InsertRoute(RouteInfo route) } private RouteInfo[] FindRouteByType(Type? typeToFind, Func mapType) - { - return FindByInheritedTypes(Mappings, typeToFind, mapType); - } + => FindByInheritedTypes(Mappings, typeToFind, mapType); private TMap[] FindByInheritedTypes(IList mappings, Type? typeToFind, Func mapType) - { - return mappings.FindByInheritedTypes(typeToFind, mapType); - } -} - -public static class TempHelpers -{ - internal static RouteInfo[] Ancestors(this RouteInfo routeInfo, IRouteResolver resolver) - { - var routes = new List(); - routeInfo.NavigatorAncestors(resolver, routes); - return routes.ToArray(); - } - - private static void NavigatorAncestors(this RouteInfo routeInfo, IRouteResolver resolver, IList 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(); - navigator.NavigatorAncestors(resolver, routes); - return routes.ToArray(); - } - - private static void NavigatorAncestors(this INavigator navigator, IRouteResolver resolver, IList 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); - } - } + => mappings.FindByInheritedTypes(typeToFind, mapType); } diff --git a/src/Uno.Extensions.Navigation.UI/RouteResolverDefault.cs b/src/Uno.Extensions.Navigation.UI/RouteResolverDefault.cs index 693fe45fc4..7172b58771 100644 --- a/src/Uno.Extensions.Navigation.UI/RouteResolverDefault.cs +++ b/src/Uno.Extensions.Navigation.UI/RouteResolverDefault.cs @@ -110,6 +110,7 @@ view is null && }); Mappings.Add(defaultMapFromViewMap); if (Logger.IsEnabled(LogLevel.Debug)) Logger.LogDebugMessage($"Created default mapping from viewmap - Path '{defaultMapFromViewMap.Path}'"); + return defaultMapFromViewMap; } if (Logger.IsEnabled(LogLevel.Information)) Logger.LogInformationMessage($"For better performance (avoid reflection), create mapping for for path '{path}', view '{view?.Name}', view model '{viewModel?.Name}'"); @@ -134,6 +135,7 @@ view is null && return IsDialogViewType(view); }); if (Logger.IsEnabled(LogLevel.Debug)) Logger.LogDebugMessage($"Created default mapping - Path '{defaultMap.Path}'"); + Mappings.Add(defaultMap); return defaultMap; } diff --git a/testing/TestHarness/TestHarness.Shared/Ext/Navigation/TabBar/TabBarHomePage.xaml b/testing/TestHarness/TestHarness.Shared/Ext/Navigation/TabBar/TabBarHomePage.xaml index 3dcf36e321..0f227a620d 100644 --- a/testing/TestHarness/TestHarness.Shared/Ext/Navigation/TabBar/TabBarHomePage.xaml +++ b/testing/TestHarness/TestHarness.Shared/Ext/Navigation/TabBar/TabBarHomePage.xaml @@ -19,6 +19,7 @@ + @@ -29,8 +30,9 @@ Grid.Row="1" x:Name="CurrentTabBarItemText" AutomationProperties.AutomationId="CurrentTabBarItemTextBlock" /> + + Grid.Row="3" > diff --git a/testing/TestHarness/TestHarness.Shared/Ext/Navigation/TabBar/TabBarHomeViewModel.cs b/testing/TestHarness/TestHarness.Shared/Ext/Navigation/TabBar/TabBarHomeViewModel.cs index bbecc14f70..e2073646e2 100644 --- a/testing/TestHarness/TestHarness.Shared/Ext/Navigation/TabBar/TabBarHomeViewModel.cs +++ b/testing/TestHarness/TestHarness.Shared/Ext/Navigation/TabBar/TabBarHomeViewModel.cs @@ -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(); + ImplicitMappingEnabled = routeResolver.ReturnImplicitMapping; + } + + [ObservableProperty] + private bool _implicitMappingEnabled; + + [RelayCommand] + public void ToggleIsChecked() + { + routeResolver.ReturnImplicitMapping = !routeResolver.ReturnImplicitMapping; + ImplicitMappingEnabled = routeResolver.ReturnImplicitMapping; + } }