Skip to content

Commit

Permalink
fix: Navigation fixes for responsive nav
Browse files Browse the repository at this point in the history
(cherry picked from commit c97f362)
  • Loading branch information
nickrandolph authored and mergify[bot] committed Jul 5, 2022
1 parent b4ea2f6 commit 906eca3
Show file tree
Hide file tree
Showing 29 changed files with 162 additions and 140 deletions.
4 changes: 2 additions & 2 deletions src/Uno.Extensions.Navigation.UI/Navigators/FrameNavigator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ viewType is null ||
}

var route = request.Route;
var segments = route.ForwardNavigationSegments(Resolver, Region, includeDependsOnRoutes: true);
var segments = route.ForwardNavigationSegments(Resolver, Region);

// As this is a forward navigation
if (segments.Length == 0)
Expand Down Expand Up @@ -128,7 +128,7 @@ viewType is null ||
// Rebuild the nested region hierarchy
Control.ReassignRegionParent();
if (segments.Length > 1 ||
string.IsNullOrWhiteSpace(request.Route.Path))
!string.IsNullOrWhiteSpace(request.Route.Path))
{
refreshViewModel = true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.Extensions.Navigation.UI/Region.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ public static IRegion GetInstance(this DependencyObject element)
return (IRegion)element.GetValue(InstanceProperty);
}

public static void SetAttached(DependencyObject element, bool value)
public static void SetAttached(this DependencyObject element, bool value)
{
element.SetValue(AttachedProperty, value);
}

public static bool GetAttached(DependencyObject element)
public static bool GetAttached(this DependencyObject element)
{
return (bool)element.GetValue(AttachedProperty);
}
Expand Down
13 changes: 10 additions & 3 deletions src/Uno.Extensions.Navigation.UI/Regions/NavigationRegion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,16 @@ public NavigationRegion(FrameworkElement? view = null, IServiceProvider? service
View = view;
if (View is not null)
{
View.Loading += ViewLoading;
View.Loaded += ViewLoaded;
View.SetInstance(this);
if (!View.IsLoaded)
{
View.Loading += ViewLoading;
View.Loaded += ViewLoaded;
}
else
{
View.Unloaded += ViewUnloaded;
}
}

if (services is not null)
Expand Down Expand Up @@ -137,7 +144,7 @@ private Task HandleLoading()

private void AssignParent()
{
if (View is null || _isRoot)
if (View is null || _isRoot || !View.GetAttached())
{
return;
}
Expand Down
23 changes: 11 additions & 12 deletions src/Uno.Extensions.Navigation.UI/RouteExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public static bool FrameIsBackNavigation(this Route route) =>
public static (Route, RouteInfo?, bool)[] ForwardNavigationSegments(
this Route route,
IRouteResolver mappings,
IRegion region,
bool includeDependsOnRoutes)
IRegion region)
{
// Here we're interested in the actual page navigation segments.
// Start with an empty list, and progressively add routes that
Expand All @@ -80,7 +79,7 @@ public static (Route, RouteInfo?, bool)[] ForwardNavigationSegments(

// For routes that have a depends on, we need to ensure that
// the dependson segments are added to the segments list
var r = includeDependsOnRoutes ? route.RootDependsOn(mappings, region, false) : route;
var r = route.RootDependsOn(mappings, region, false);
var map = mappings.Find(r);
var originalRoute = false;
while (
Expand Down Expand Up @@ -375,7 +374,7 @@ public static IDictionary<string, object> AsParameters(this IDictionary<string,
}
else
{
var segments = currentRoute.ForwardNavigationSegments(resolver, region, includeDependsOnRoutes: false).ToList();
var segments = currentRoute.ForwardNavigationSegments(resolver, region).ToList();
foreach (var qualifierChar in qualifier)
{
if (qualifierChar + "" == Qualifiers.NavigateBack)
Expand All @@ -388,7 +387,7 @@ public static IDictionary<string, object> AsParameters(this IDictionary<string,
}
}

var newSegments = frameRoute.ForwardNavigationSegments(resolver, region, includeDependsOnRoutes: true);
var newSegments = frameRoute.ForwardNavigationSegments(resolver, region);
if (newSegments is not null)
{
newSegments = (from seg in newSegments
Expand All @@ -412,13 +411,13 @@ public static IDictionary<string, object> AsParameters(this IDictionary<string,
public static Route RootDependsOn(this Route currentRoute, IRouteResolver resolver, IRegion region, bool includeCurrentRegion)
{
var rm = resolver.FindByPath(currentRoute.Base);
if ((rm is null ||
string.IsNullOrEmpty(rm.DependsOn)) &&
region.Navigator()?.Route?.Base == currentRoute.Base &&
!includeCurrentRegion)
{
return Route.Empty;
}
//if ((rm is null ||
// string.IsNullOrEmpty(rm.DependsOn)) &&
// region.Navigator()?.Route?.Base == currentRoute.Base &&
// !includeCurrentRegion)
//{
// return Route.Empty;
//}

while (rm is not null &&
!string.IsNullOrEmpty(rm.DependsOn))
Expand Down
15 changes: 8 additions & 7 deletions testing/TestHarness/TestHarness.Mobile/TestHarness.Mobile.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="7.1.2" />
<PackageReference Include="Uno.CommunityToolkit.WinUI.UI" Version="7.1.100-dev.15.g12261e2626" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.44.0" />
<PackageReference Include="Uno.WinUI" Version="4.3.8" />
<PackageReference Include="Uno.WinUI.RemoteControl" Version="4.3.8" Condition="'$(Configuration)'=='Debug'" />
<PackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" Version="4.3.8" />
<PackageReference Include="Uno.WinUI" Version="4.4.5" />
<PackageReference Include="Uno.WinUI.RemoteControl" Version="4.4.5" Condition="'$(Configuration)'=='Debug'" />
<PackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" Version="4.4.5" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Refit" Version="6.3.2" />
<PackageReference Include="Refit.HttpClientFactory" Version="6.3.2" />
<PackageReference Include="System.Text.Json" Version="6.0.3" />
<!--<PackageReference Include="Uno.Material.WinUI" Version="2.1.0" />
<PackageReference Include="Uno.Toolkit.WinUI.Material" Version="2.1.0" />-->
<PackageReference Include="Uno.Toolkit.WinUI" Version="2.1.0" />
<PackageReference Include="Uno.WinUI.MSAL" Version="4.3.8" />
<PackageReference Include="Uno.Material.WinUI" Version="2.2.0" />
<PackageReference Include="Uno.Toolkit.WinUI.Material" Version="2.2.0" />
<PackageReference Include="Uno.Toolkit.WinUI" Version="2.2.0" />
<PackageReference Include="Uno.WinUI.MSAL" Version="4.4.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Uno.Extensions.Authentication\Uno.Extensions.Authentication.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
xmlns:utu="using:Uno.Toolkit.UI"
xmlns:uen="using:Uno.Extensions.Navigation.UI"
xmlns:um="using:Uno.Material"
xmlns:triggers="using:CommunityToolkit.WinUI.UI.Triggers"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
NavigationCacheMode="Required">

<Grid>
<Grid x:Name="ParentGrid">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualStateGroup CurrentStateChanged="ResponsiveStateChanged">
<VisualState x:Name="Wide">
<VisualState.StateTriggers>
<triggers:ControlSizeTrigger MinWidth="{StaticResource WideMinWindowWidth}"
TargetElement="{Binding ElementName=ParentGrid}" />
</VisualState.StateTriggers>
<VisualState.Setters>
<!--<Setter Target="DealsListView.SelectionMode"
Value="Single" />
Expand All @@ -34,6 +39,9 @@
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Narrow">
<VisualState.StateTriggers>
<triggers:ControlSizeTrigger MinWidth="0" />
</VisualState.StateTriggers>
<VisualState.Setters>
<!--<Setter Target="DealsListView.SelectionMode"
Value="None" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

using System.Diagnostics;

namespace TestHarness.Ext.Navigation.Apps.Commerce;

public sealed partial class CommerceDealsPage : Page
Expand All @@ -7,7 +9,11 @@ public sealed partial class CommerceDealsPage : Page
public CommerceDealsPage()
{
this.InitializeComponent();
}

this.ApplyAdaptiveTrigger(App.Current.Resources["WideMinWindowWidth"] is double width ? width : 0.0, nameof(Narrow), nameof(Wide));
private void ResponsiveStateChanged(object sender, VisualStateChangedEventArgs e)
{
Debug.WriteLine("State Changed");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,17 @@
xmlns:uen="using:Uno.Extensions.Navigation.UI"
xmlns:um="using:Uno.Material"
mc:Ignorable="d"
xmlns:triggers="using:CommunityToolkit.WinUI.UI.Triggers"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
<Grid x:Name="ParentGrid">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Narrow">

<VisualState.Setters>
<Setter Target="Tabs.Visibility"
Value="Visible" />
<Setter Target="NavView.IsPaneToggleButtonVisible"
Value="false" />
<Setter Target="NavView.PaneDisplayMode"
Value="LeftMinimal" />
<Setter Target="NavView.IsPaneOpen"
Value="False" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Wide">
<VisualState.StateTriggers>
<triggers:ControlSizeTrigger MinWidth="{StaticResource WideMinWindowWidth}"
TargetElement="{Binding ElementName=ParentGrid}" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="Tabs.Visibility"
Value="Collapsed" />
Expand All @@ -39,6 +31,22 @@
Value="Auto" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Narrow">
<VisualState.StateTriggers>
<triggers:ControlSizeTrigger MinWidth="0" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="Tabs.Visibility"
Value="Visible" />
<Setter Target="NavView.IsPaneToggleButtonVisible"
Value="false" />
<Setter Target="NavView.PaneDisplayMode"
Value="LeftMinimal" />
<Setter Target="NavView.IsPaneOpen"
Value="False" />
</VisualState.Setters>
</VisualState>

</VisualStateGroup>
</VisualStateManager.VisualStateGroups>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public CommerceHomePage()
{
this.InitializeComponent();

this.ApplyAdaptiveTrigger(App.Current.Resources["WideMinWindowWidth"] is double width ? width : 0.0, nameof(Narrow), nameof(Wide));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
xmlns:utu="using:Uno.Toolkit.UI"
xmlns:uen="using:Uno.Extensions.Navigation.UI"
xmlns:um="using:Uno.Material"
xmlns:triggers="using:CommunityToolkit.WinUI.UI.Triggers"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
NavigationCacheMode="Required">

<Grid>
<Grid x:Name="ParentGrid">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Wide">
<VisualState.StateTriggers>
<triggers:ControlSizeTrigger MinWidth="{StaticResource WideMinWindowWidth}"
TargetElement="{Binding ElementName=ParentGrid}" />
</VisualState.StateTriggers>
<VisualState.Setters>
<!--<Setter Target="ProductsListView.SelectionMode"
Value="Single" />-->
Expand All @@ -34,6 +39,9 @@
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Narrow">
<VisualState.StateTriggers>
<triggers:ControlSizeTrigger MinWidth="0" />
</VisualState.StateTriggers>
<VisualState.Setters>
<!--<Setter Target="ProductsListView.SelectionMode"
Value="None" />-->
Expand Down Expand Up @@ -75,6 +83,7 @@
</ListView>
<Grid Grid.Column="1"
x:Name="DetailsGrid"
Background="LightPink"
Visibility="Collapsed">
<ContentControl x:Name="Details"
uen:Region.Attached="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public CommerceProductsPage()
{
this.InitializeComponent();

this.ApplyAdaptiveTrigger(App.Current.Resources["WideMinWindowWidth"] is double width ? width : 0.0, nameof(Narrow), nameof(Wide));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
xmlns:utu="using:Uno.Toolkit.UI"
xmlns:uen="using:Uno.Extensions.Navigation.UI"
xmlns:um="using:Uno.Material"
xmlns:triggers="using:CommunityToolkit.WinUI.UI.Triggers"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
NavigationCacheMode="Required">

<Grid>
<Grid x:Name="ParentGrid">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Wide">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource WideMinWindowWidth}" />
<triggers:ControlSizeTrigger MinWidth="{StaticResource WideMinWindowWidth}"
TargetElement="{Binding ElementName=ParentGrid}" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="NavView.(uen:Navigation.Request)"
Expand All @@ -26,7 +28,8 @@
</VisualState>
<VisualState x:Name="Narrow">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="0" />
<triggers:ControlSizeTrigger MinWidth="0"
TargetElement="{Binding ElementName=ParentGrid}" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="NavView.(uen:Navigation.Request)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public ToDoHomePage()
{
this.InitializeComponent();

this.ApplyAdaptiveTrigger(App.Current.Resources["WideMinWindowWidth"] is double width ? width : 0.0, nameof(Narrow), nameof(Wide));


}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
xmlns:utu="using:Uno.Toolkit.UI"
xmlns:uen="using:Uno.Extensions.Navigation.UI"
xmlns:um="using:Uno.Material"
xmlns:triggers="using:CommunityToolkit.WinUI.UI.Triggers"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
NavigationCacheMode="Required">
Expand All @@ -18,11 +19,15 @@
FontSize="32" />
</DataTemplate>
</Page.Resources>
<Grid>

<Grid x:Name="ParentGrid">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Wide">
<VisualState.StateTriggers>
<triggers:ControlSizeTrigger MinWidth="{StaticResource WideMinWindowWidth}"
TargetElement="{Binding ElementName=ParentGrid}" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="TaskListColumn.Width"
Value="*" />
Expand All @@ -37,6 +42,10 @@
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Narrow">
<VisualState.StateTriggers>
<triggers:ControlSizeTrigger MinWidth="0"
TargetElement="{Binding ElementName=ParentGrid}" />
</VisualState.StateTriggers>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public ToDoTaskListPage()
{
this.InitializeComponent();

this.ApplyAdaptiveTrigger(App.Current.Resources["WideMinWindowWidth"] is double width ? width : 0.0, nameof(Narrow), nameof(Wide));


}

Expand Down
Loading

0 comments on commit 906eca3

Please sign in to comment.