Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Adding default routes for hard coded regions #2152

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading