Skip to content

Commit

Permalink
Merge pull request #2152 from unoplatform/dev/nr/noroutetabs
Browse files Browse the repository at this point in the history
fix: Adding default routes for hard coded regions
  • Loading branch information
nickrandolph authored Jan 22, 2024
2 parents c17484a + ae07ea6 commit cabea8b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 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 @@ -549,6 +549,7 @@ protected virtual async Task<bool> RegionCanNavigate(Route route, RouteInfo? rou
if (currentRouteMap != null || routeMap != null)
{
if (routeMap?.Parent is not null &&
currentRouteMap?.Parent is not null &&
currentRouteMap?.Parent != routeMap.Parent)
{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ public PanelVisiblityNavigator(
RegionControlProvider controlProvider)
: base(logger, dispatcher, region, resolver, controlProvider.RegionControl as Grid)
{
if (region.View is not null)
{
region.View.Loaded += PanelLoaded;
}
}

private void PanelLoaded(object sender, RoutedEventArgs e) {
if (Control is null)
{
return;
}
Control.Loaded -= PanelLoaded;

var existingRoutes =
Control.Children.OfType<FrameworkElement>().Select(x => x.GetName()).Where(x => x is { Length: > 0 });
existingRoutes.ForEach(r => Resolver.InsertRoute(new RouteInfo(r))).ToArray();
}

protected override async Task<bool> RegionCanNavigate(Route route, RouteInfo? routeMap)
Expand All @@ -23,7 +39,7 @@ protected override async Task<bool> RegionCanNavigate(Route route, RouteInfo? ro
return false;
}

if(routeMap?.RenderView?.IsSubclassOf(typeof(FrameworkElement)) ?? false)
if (routeMap?.RenderView?.IsSubclassOf(typeof(FrameworkElement)) ?? false)
{
return true;
}
Expand Down
10 changes: 10 additions & 0 deletions src/Uno.Extensions.Navigation.UI/RouteResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ protected virtual RouteInfo[] InternalFindByView(Type? viewType)
return BestNavigatorRouteInfo(maps, navigator);
}

/// <inheritdoc />
public void InsertRoute(RouteInfo route)
{
var path = route.Path;
if (Mappings.FirstOrDefault(x => x.Path == path) is not { })
{
Mappings.Add(route);
}
}

private RouteInfo[] FindRouteByType(Type? typeToFind, Func<RouteInfo, Type?> mapType)
{
return FindByInheritedTypes(Mappings, typeToFind, mapType);
Expand Down
2 changes: 2 additions & 0 deletions src/Uno.Extensions.Navigation/IRouteResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface IRouteResolver
RouteInfo? FindByData(Type? dataType, INavigator? navigator);

RouteInfo? FindByResultData(Type? resultDataType, INavigator? navigator);

void InsertRoute(RouteInfo routeInfo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ protected override void RegisterRoutes(IViewRegistry views, IRouteRegistry route
new RouteMap("",
Nested: new[]
{
new RouteMap("Home", View: views.FindByViewModel<TabBarHomeViewModel>()),
new RouteMap("Home", View: views.FindByViewModel<TabBarHomeViewModel>(), Nested:
new RouteMap[]
{
new RouteMap("Products"),

}),
new RouteMap("List", View: views.FindByViewModel<TabBarListViewModel>(), Nested:
new RouteMap[]
{
Expand Down

0 comments on commit cabea8b

Please sign in to comment.