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: Closure of flyout when no route set on the flyoutnavigator #2338

Merged
merged 6 commits into from
Jun 12, 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
27 changes: 23 additions & 4 deletions src/Uno.Extensions.Navigation.UI/Navigator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Diagnostics;
using Uno.Extensions.Diagnostics;
using Uno.Extensions.Navigation.UI;
using Uno.Extensions.Diagnostics;

namespace Uno.Extensions.Navigation;

Expand Down Expand Up @@ -202,7 +200,7 @@ await RedirectForDependsOn(request, rm) is { } dependsNavResponse)

if (Logger.IsEnabled(LogLevel.Trace)) Logger.LogTraceMessage($"Building fully qualified route for unhandled request. New request: {request.Route}");

if(Region.Navigator() is ClosableNavigator closable)
if (Region.Navigator() is ClosableNavigator closable)
{
if (Logger.IsEnabled(LogLevel.Trace)) Logger.LogTraceMessage($"Closing navigator and redirecting request");
return closable.CloseAndNavigateAsync(request);
Expand Down Expand Up @@ -557,6 +555,27 @@ protected virtual async Task<bool> RegionCanNavigate(Route route, RouteInfo? rou
}
}

// If a flyout is hosting a page it will inject frameview
// resulting in an empty route for the flyout navigator.
// In this case we need to check the child regions for a route
// and use that to determine if the current navigator should be
// closed (ie we can navigate to the current route inside the flyout)
if (this is ClosableNavigator closable &&
Route?.IsEmpty() == true &&
Region.Children.FirstOrDefault(x => x.Navigator()?.Route?.IsEmpty() == false) is { } childRegion)
{
var currentRouteMap = Resolver.FindByPath(childRegion.Navigator()?.Route?.Base);
if (currentRouteMap != null || routeMap != null)
{
if (routeMap?.Parent is not null &&
currentRouteMap?.Parent is not null &&
currentRouteMap?.Parent != routeMap.Parent)
{
return false;
}
}
}

return true;
}

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 @@ -12,6 +12,7 @@ public enum TestSections
Navigation_NavigationView,
Navigation_TabBar,
Navigation_Reactive,
Apps_Chefs,
Apps_Commerce,
Apps_Commerce_ShellControl,
Apps_ToDo,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<ContentDialog x:Class="TestHarness.Ext.Navigation.Apps.Chefs.ChefsCompletedDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestHarness.Ext.Navigation.Apps.Chefs"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
<TextBlock Text="Completed" />
</Grid>
</ContentDialog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

namespace TestHarness.Ext.Navigation.Apps.Chefs;

public sealed partial class ChefsCompletedDialog : ContentDialog
{
public ChefsCompletedDialog()
{
this.InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace TestHarness.Ext.Navigation.Apps.Chefs;

public partial class ChefsCookbookDetailModel
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Page x:Class="TestHarness.Ext.Navigation.Apps.Chefs.ChefsCookbookDetailPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestHarness.Ext.Navigation.Apps.Chefs"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
<TextBlock Text="ChefsCookbookDetail" />
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

namespace TestHarness.Ext.Navigation.Apps.Chefs;

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

public partial class ChefsCreateUpdateCookbookModel
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Page x:Class="TestHarness.Ext.Navigation.Apps.Chefs.ChefsCreateUpdateCookbookPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestHarness.Ext.Navigation.Apps.Chefs"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
<TextBlock Text="ChefsCreateUpdateCookbook" />
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

namespace TestHarness.Ext.Navigation.Apps.Chefs;

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

public partial class ChefsFavoriteRecipesModel
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Page x:Class="TestHarness.Ext.Navigation.Apps.Chefs.ChefsFavoriteRecipesPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestHarness.Ext.Navigation.Apps.Chefs"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
<TextBlock Text="ChefsFavoriteRecipes" />
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

namespace TestHarness.Ext.Navigation.Apps.Chefs;

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

public partial class ChefsFilterModel
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Page x:Class="TestHarness.Ext.Navigation.Apps.Chefs.ChefsFilterPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestHarness.Ext.Navigation.Apps.Chefs"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
<TextBlock Text="ChefsFilter" />
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

namespace TestHarness.Ext.Navigation.Apps.Chefs;

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

<Grid>
<TextBlock Text="Generic" />
</Grid>
</ContentDialog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

namespace TestHarness.Ext.Navigation.Apps.Chefs;

public sealed partial class ChefsGenericDialog : ContentDialog
{
public ChefsGenericDialog()
{
this.InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace TestHarness.Ext.Navigation.Apps.Chefs;

public partial class ChefsGenericDialogModel
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using TestHarness.Ext.Navigation.Apps.Chefs.Models;

namespace TestHarness.Ext.Navigation.Apps.Chefs;

public partial class ChefsHomeModel(INavigator navigator)
{

public async ValueTask ShowCurrentProfile()
{
await navigator.NavigateToProfile(this, new ChefsUser { FullName = "Tester User" });
}

public async ValueTask ShowCurrentProfileNew()
{
await navigator.NavigateRouteAsync(this, "ChefsProfile", qualifier: Qualifiers.Dialog, data: new ChefsUser { FullName = "Tester User (new)" });
}


}

public static class ChefsNavigationExtensions
{
public static async ValueTask NavigateToProfile(this INavigator navigator, object sender, ChefsUser? profile = null)
{
var response = await navigator.NavigateRouteForResultAsync<ChefsRecipe?>(sender, "ChefsProfile", qualifier: Qualifiers.Dialog, data: profile);
var result = await response!.Result;

//If a Recipe was selected, navigate to the RecipeDetails. Otherwise, do nothing
await (result.SomeOrDefault() switch
{
ChefsRecipe recipe => navigator.NavigateDataAsync(sender, recipe),
_ => Task.CompletedTask,
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Page x:Class="TestHarness.Ext.Navigation.Apps.Chefs.ChefsHomePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestHarness.Ext.Navigation.Apps.Chefs"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<StackPanel>
<TextBlock Text="ChefsHome" />
<Button Content="Profile"
Command="{Binding ShowCurrentProfile}" />
<Button Content="Profile (New)"
Command="{Binding ShowCurrentProfileNew}" />
</StackPanel>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

namespace TestHarness.Ext.Navigation.Apps.Chefs;

public sealed partial class ChefsHomePage : Page
{
public ChefsHomePage()
{
this.InitializeComponent();
}
}
Loading
Loading