Skip to content

Commit

Permalink
Merge pull request #2409 from unoplatform/dev/erli/region-sample
Browse files Browse the repository at this point in the history
fix: Remove unnecessary request segments from parent region in backstack
  • Loading branch information
eriklimakc authored Aug 9, 2024
2 parents 8172123 + 60c70ff commit f677bd2
Show file tree
Hide file tree
Showing 21 changed files with 523 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Uno.Extensions.Navigation.UI/Navigators/FrameNavigator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ viewType is null ||
RemoveLastFromBackStack();
}

var parentRegion = this.Region.Parent;
while (parentRegion is { } &&
parentRegion.Name is null)
{
parentRegion = parentRegion.Parent;
}

for (var i = 0; i < segments.Length - 1; i++)
{
Expand All @@ -160,6 +166,11 @@ viewType is null ||
continue;
}

if (parentRegion?.Name == map.Path)
{
continue;
}

var newEntry = new PageStackEntry(
map.RenderView,
request.Route.NavigationData(),
Expand Down
1 change: 1 addition & 0 deletions testing/TestHarness/TestHarness.Core/TestSections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum TestSections
Apps_Commerce,
Apps_Commerce_ShellControl,
Apps_ToDo,
Apps_Regions,
Authentication_Custom,
Authentication_Custom_Service,
Authentication_Custom_TestBackend,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,53 @@ public async Task When_ToDo_Responsive()

}

[Test]
public async Task When_ToDo_Wide_Nav_ContentControl()
{
InitTestSection(TestSections.Apps_ToDo);

App.WaitThenTap("ShowAppButton");

// Make sure the app has loaded
App.WaitElement("WelcomeNavigationBar");

// Login
await App.TapAndWait("LoginButton", "HomeNavigationBar");

// Select a task list
await App.TapAndWait("SelectTaskList2Button", "TaskListNavigationBar");

await App.TapAndWait("SelectActiveTask1Button", "TaskNavigationBar");

var screenBefore = TakeScreenshot("When_ToDo_Wide_Nav_ContentControl_Before");

await App.TapAndWait("DetailsBackButton", "TaskListNavigationBar");

var screenAfter = TakeScreenshot("When_ToDo_Wide_Nav_ContentControl_After");

ImageAssert.AreEqual(screenBefore, screenAfter, tolerance: PixelTolerance.Exclusive(Constants.DefaultPixelTolerance));
}

[Test]
public async Task When_ToDo_Narrow_Nav_ContentControl()
{
InitTestSection(TestSections.Apps_ToDo);

App.WaitThenTap("ShowAppButton");

App.WaitThenTap("NarrowButton");

// Make sure the app has loaded
App.WaitElement("WelcomeNavigationBar");

// Login
await App.TapAndWait("LoginButton", "HomeNavigationBar");

// Select a task list
await App.TapAndWait("SelectTaskList2Button", "TaskListNavigationBar");

await App.TapAndWait("SelectActiveTask1Button", "TaskNavigationBar");

await App.TapAndWait("DetailsBackButton", "TaskListNavigationBar");
}
}
3 changes: 3 additions & 0 deletions testing/TestHarness/TestHarness/Assets/Images/back.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace TestHarness.Ext.Navigation.Apps.Regions;

public class FourthData
{
public string Name { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<Page x:Class="TestHarness.Ext.Navigation.Apps.Regions.RegionsFirstPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:TestHarness.Ext.Navigation.Apps.Regions"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:uen="using:Uno.Extensions.Navigation.UI"
xmlns:utu="using:Uno.Toolkit.UI"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">

<Grid uen:Region.Attached="True">

<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>

<utu:NavigationBar Content="First Page" Style="{StaticResource MaterialNavigationBarStyle}">
<utu:NavigationBar.MainCommand>
<AppBarButton uen:Navigation.Request="-" Foreground="{ThemeResource OnSurfaceInverseBrush}">
<AppBarButton.Icon>
<BitmapIcon UriSource="ms-appx:///Assets/Images/back.png" />
</AppBarButton.Icon>
</AppBarButton>
</utu:NavigationBar.MainCommand>
</utu:NavigationBar>

<Grid Grid.Row="1"
uen:Region.Attached="True"
uen:Region.Navigator="Visibility">
<Grid uen:Region.Name="RegionsOne" Visibility="Collapsed">
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="24"
Text="One" />
</Grid>
<Grid uen:Region.Name="RegionsTwo" Visibility="Collapsed">
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="24"
Text="Two" />
</Grid>
<Grid uen:Region.Name="RegionsThree" Visibility="Collapsed">
<Frame uen:Region.Attached="True">
<StackPanel>
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="24"
Text="Three" />
</StackPanel>
</Frame>
</Grid>
</Grid>
<utu:TabBar Grid.Row="2"
VerticalAlignment="Bottom"
uen:Region.Attached="True">
<utu:TabBar.Items>
<utu:TabBarItem uen:Region.Name="RegionsOne" Content="One" />
<utu:TabBarItem uen:Region.Name="RegionsTwo" Content="Two" />
<utu:TabBarItem uen:Region.Name="RegionsThree" Content="Three" />
</utu:TabBar.Items>
</utu:TabBar>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace TestHarness.Ext.Navigation.Apps.Regions;

public sealed partial class RegionsFirstPage : Page
{
public RegionsFirstPage()
{
this.InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Page x:Class="TestHarness.Ext.Navigation.Apps.Regions.RegionsFourthPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:TestHarness.Ext.Navigation.Apps.Regions"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:utu="using:Uno.Toolkit.UI"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">

<Grid utu:SafeArea.Insets="VisibleBounds">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<utu:NavigationBar Content="Fourth Page">
<utu:NavigationBar.MainCommand>
<AppBarButton>
<AppBarButton.Icon>
<BitmapIcon UriSource="ms-appx:///Assets/Images/back.png" />
</AppBarButton.Icon>
</AppBarButton>
</utu:NavigationBar.MainCommand>
</utu:NavigationBar>
<StackPanel Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBlock Margin="8"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{Binding FourthData.Name}" />
</StackPanel>

</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace TestHarness.Ext.Navigation.Apps.Regions;

public sealed partial class RegionsFourthPage : Page
{
public RegionsFourthPage()
{
this.InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace TestHarness.Ext.Navigation.Apps.Regions;

public class RegionsFourthViewModel (FourthData fourthData)
{
public FourthData FourthData { get; set; } = fourthData;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<Page x:Class="TestHarness.Ext.Navigation.Apps.Regions.RegionsHomePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:TestHarness.Ext.Navigation.Apps.Regions"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:uen="using:Uno.Extensions.Navigation.UI"
xmlns:utu="using:Uno.Toolkit.UI"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">

<Grid>
<muxc:NavigationView Grid.Row="1"
uen:Region.Attached="True"
IsBackButtonVisible="Collapsed"
IsPaneOpen="True"
IsSettingsVisible="False"
OpenPaneLength="200"
PaneDisplayMode="Auto">
<muxc:NavigationView.MenuItems>

<muxc:NavigationViewItem uen:Region.Name="RegionsFirst" Content="First Page">
<muxc:NavigationViewItem.Icon>
<SymbolIcon Symbol="Accept" />
</muxc:NavigationViewItem.Icon>
</muxc:NavigationViewItem>

<muxc:NavigationViewItem uen:Region.Name="RegionsSecond" Content="Second Page">
<muxc:NavigationViewItem.Icon>
<SymbolIcon Symbol="Share" />
</muxc:NavigationViewItem.Icon>
</muxc:NavigationViewItem>

<muxc:NavigationViewItem uen:Region.Name="RegionsThird" Content="Third Page">
<muxc:NavigationViewItem.Icon>
<SymbolIcon Symbol="OutlineStar" />
</muxc:NavigationViewItem.Icon>
</muxc:NavigationViewItem>

</muxc:NavigationView.MenuItems>

<Grid x:Name="NavigationGrid"
Grid.Column="1"
uen:Region.Attached="True"
uen:Region.Navigator="Visibility" />
</muxc:NavigationView>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace TestHarness.Ext.Navigation.Apps.Regions
{
public sealed partial class RegionsHomePage : Page
{
public RegionsHomePage()
{
this.InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace TestHarness.Ext.Navigation.Apps.Regions;

public partial class RegionsHostInit : BaseHostInitialization
{
protected override void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
{
views.Register(
new ViewMap(ViewModel: typeof(RegionsShellModel)),
new ViewMap<RegionsHomePage>(),
new ViewMap<RegionsFirstPage>(),
new ViewMap<RegionsSecondPage, RegionsSecondViewModel>(),
new ViewMap<RegionsThirdPage>(),
new DataViewMap<RegionsFourthPage, RegionsFourthViewModel, FourthData>()
);

routes.Register(
new RouteMap("", View: views.FindByViewModel<RegionsShellModel>(),
Nested:
[
new ("RegionsHome", View: views.FindByView<RegionsHomePage>(),
Nested:
[
new ("RegionsFirst", View: views.FindByView<RegionsFirstPage>(), IsDefault: true,
Nested:
[
new ("RegionsOne", IsDefault: true),
new ("RegionsTwo"),
new ("RegionsThree")
]
),
new ("RegionsSecond", View: views.FindByViewModel<RegionsSecondViewModel>()),
new ("RegionsThird", View: views.FindByView<RegionsThirdPage>()),
new ("RegionsFourth", View: views.FindByViewModel<RegionsFourthViewModel>(), DependsOn: "RegionsSecond")
]),
]
)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<testharness:BaseTestSectionPage x:Class="TestHarness.Ext.Navigation.Apps.Regions.RegionsMainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:TestHarness.Ext.Navigation.Apps.Regions"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:testharness="using:TestHarness"
xmlns:uen="using:Uno.Extensions.Navigation.UI"
xmlns:utu="using:Uno.Toolkit.UI"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Margin="20"
FontSize="30"
Text="Sample App: Regions Tests" />
<ScrollViewer Grid.Row="1"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollMode="Auto"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollMode="Disabled">
<Border HorizontalAlignment="Left"
VerticalAlignment="Stretch"
BorderBrush="Black"
BorderThickness="2">

<utu:ExtendedSplashScreen x:Name="NavigationRoot"
Width="1920"
HorizontalAlignment="Left"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
AutomationProperties.AutomationId="NavigationRoot" />
</Border>
</ScrollViewer>
<StackPanel Grid.Row="2"
HorizontalAlignment="Center"
Orientation="Horizontal">
<Button AutomationProperties.AutomationId="ShowAppButton"
Click="ShowAppClick"
Content="Regions App" />
<Button AutomationProperties.AutomationId="NarrowButton"
Click="NarrowClick"
Content="Narrow" />
<Button AutomationProperties.AutomationId="WideButton"
Click="WideClick"
Content="Wide" />
</StackPanel>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="NarrowWindow">
<VisualState.Setters>
<Setter Target="NavigationRoot.Width" Value="400" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="WideWindow" />

</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</testharness:BaseTestSectionPage>
Loading

0 comments on commit f677bd2

Please sign in to comment.