mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Router - Require routable VMs to implement new RoutableScreen
This commit is contained in:
1 parent
318ec99ad4
commit
c132edeb51
43 files changed
+284
-287
No files matched your search
@@ -0,0 +1,13 @@
|
||||
namespace Artemis.UI.Shared.Routing;
|
||||
|
||||
/// <summary>
|
||||
/// For internal use.
|
||||
/// </summary>
|
||||
/// <seealso cref="RoutableHostScreen{TScreen}" />
|
||||
/// <seealso cref="RoutableHostScreen{TScreen,TParam}" />
|
||||
internal interface IRoutableHostScreen : IRoutableScreen
|
||||
{
|
||||
bool RecycleScreen { get; }
|
||||
IRoutableScreen? InternalScreen { get; }
|
||||
void InternalChangeScreen(IRoutableScreen? screen);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Shared.Routing;
|
||||
|
||||
/// <summary>
|
||||
/// For internal use.
|
||||
/// </summary>
|
||||
internal interface IRoutableScreen : IActivatableViewModel
|
||||
{
|
||||
Task InternalOnNavigating(NavigationArguments args, CancellationToken cancellationToken);
|
||||
Task InternalOnClosing(NavigationArguments args);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
namespace Artemis.UI.Shared.Routing;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a view model to which routing can take place and which in turn can host another view model.
|
||||
/// </summary>
|
||||
/// <typeparam name="TScreen">The type of view model the screen can host.</typeparam>
|
||||
public abstract class RoutableHostScreen<TScreen> : RoutableScreen, IRoutableHostScreen where TScreen : RoutableScreen
|
||||
{
|
||||
private bool _recycleScreen = true;
|
||||
private TScreen? _screen;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently active child screen.
|
||||
/// </summary>
|
||||
public TScreen? Screen
|
||||
{
|
||||
get => _screen;
|
||||
private set => RaiseAndSetIfChanged(ref _screen, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool RecycleScreen
|
||||
{
|
||||
get => _recycleScreen;
|
||||
protected set => RaiseAndSetIfChanged(ref _recycleScreen, value);
|
||||
}
|
||||
|
||||
IRoutableScreen? IRoutableHostScreen.InternalScreen => Screen;
|
||||
|
||||
void IRoutableHostScreen.InternalChangeScreen(IRoutableScreen? screen)
|
||||
{
|
||||
if (screen == null)
|
||||
{
|
||||
Screen = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (screen is not TScreen typedScreen)
|
||||
throw new ArtemisRoutingException($"Screen cannot be hosted, {screen.GetType().Name} is not assignable to {typeof(TScreen).Name}.");
|
||||
Screen = typedScreen;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
namespace Artemis.UI.Shared.Routing;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a view model to which routing with parameters can take place and which in turn can host another view
|
||||
/// model.
|
||||
/// </summary>
|
||||
/// <typeparam name="TScreen">The type of view model the screen can host.</typeparam>
|
||||
/// <typeparam name="TParam">The type of parameters the screen expects. It must have a parameterless constructor.</typeparam>
|
||||
public abstract class RoutableHostScreen<TScreen, TParam> : RoutableScreen<TParam>, IRoutableHostScreen where TScreen : RoutableScreen where TParam : new()
|
||||
{
|
||||
private bool _recycleScreen = true;
|
||||
private TScreen? _screen;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently active child screen.
|
||||
/// </summary>
|
||||
public TScreen? Screen
|
||||
{
|
||||
get => _screen;
|
||||
private set => RaiseAndSetIfChanged(ref _screen, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool RecycleScreen
|
||||
{
|
||||
get => _recycleScreen;
|
||||
protected set => RaiseAndSetIfChanged(ref _recycleScreen, value);
|
||||
}
|
||||
|
||||
IRoutableScreen? IRoutableHostScreen.InternalScreen => Screen;
|
||||
|
||||
void IRoutableHostScreen.InternalChangeScreen(IRoutableScreen? screen)
|
||||
{
|
||||
if (screen == null)
|
||||
{
|
||||
Screen = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (screen is not TScreen typedScreen)
|
||||
throw new ArtemisRoutingException($"Screen cannot be hosted, {screen.GetType().Name} is not assignable to {typeof(TScreen).Name}.");
|
||||
Screen = typedScreen;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,55 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Shared.Routing;
|
||||
|
||||
/// <summary>
|
||||
/// For internal use.
|
||||
/// Represents a view model to which routing can take place.
|
||||
/// </summary>
|
||||
/// <seealso cref="RoutableScreen{TScreen}"/>
|
||||
/// <seealso cref="RoutableScreen{TScreen, TParam}"/>
|
||||
internal interface IRoutableScreen : IActivatableViewModel
|
||||
public abstract class RoutableScreen : ActivatableViewModelBase, IRoutableScreen
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not to reuse the child screen instance if the type has not changed.
|
||||
/// Called before navigating to this screen.
|
||||
/// </summary>
|
||||
/// <remarks>Defaults to <see langword="true"/>.</remarks>
|
||||
bool RecycleScreen { get; }
|
||||
/// <param name="args">Navigation arguments containing information about the navigation action.</param>
|
||||
public virtual Task BeforeNavigating(NavigationArguments args)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
object? InternalScreen { get; }
|
||||
void InternalChangeScreen(object? screen);
|
||||
Task InternalOnNavigating(NavigationArguments args, CancellationToken cancellationToken);
|
||||
Task InternalOnClosing(NavigationArguments args);
|
||||
/// <summary>
|
||||
/// Called while navigating to this screen.
|
||||
/// </summary>
|
||||
/// <param name="args">Navigation arguments containing information about the navigation action.</param>
|
||||
/// <param name="cancellationToken">
|
||||
/// A cancellation token that can be used by other objects or threads to receive notice of
|
||||
/// cancellation.
|
||||
/// </param>
|
||||
public virtual Task OnNavigating(NavigationArguments args, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called before navigating away from this screen.
|
||||
/// </summary>
|
||||
/// <param name="args">Navigation arguments containing information about the navigation action.</param>
|
||||
public virtual Task OnClosing(NavigationArguments args)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
#region Overrides of RoutableScreen
|
||||
|
||||
async Task IRoutableScreen.InternalOnNavigating(NavigationArguments args, CancellationToken cancellationToken)
|
||||
{
|
||||
await OnNavigating(args, cancellationToken);
|
||||
}
|
||||
|
||||
async Task IRoutableScreen.InternalOnClosing(NavigationArguments args)
|
||||
{
|
||||
await OnClosing(args);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
+4
-62
@@ -4,39 +4,15 @@ using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Platform;
|
||||
|
||||
namespace Artemis.UI.Shared.Routing;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a view model to which routing with parameters can take place and which in turn can host another view
|
||||
/// model.
|
||||
/// Represents a view model to which routing with parameters can take place.
|
||||
/// </summary>
|
||||
/// <typeparam name="TScreen">The type of view model the screen can host.</typeparam>
|
||||
/// <typeparam name="TParam">The type of parameters the screen expects. It must have a parameterless constructor.</typeparam>
|
||||
public abstract class RoutableScreen<TScreen, TParam> : ActivatableViewModelBase, IRoutableScreen where TScreen : class where TParam : new()
|
||||
public abstract class RoutableScreen<TParam> : RoutableScreen, IRoutableScreen where TParam : new()
|
||||
{
|
||||
private bool _recycleScreen = true;
|
||||
private TScreen? _screen;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently active child screen.
|
||||
/// </summary>
|
||||
public TScreen? Screen
|
||||
{
|
||||
get => _screen;
|
||||
private set => RaiseAndSetIfChanged(ref _screen, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called before navigating to this screen.
|
||||
/// </summary>
|
||||
/// <param name="args">Navigation arguments containing information about the navigation action.</param>
|
||||
public virtual Task BeforeNavigating(NavigationArguments args)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called while navigating to this screen.
|
||||
/// </summary>
|
||||
@@ -50,40 +26,7 @@ public abstract class RoutableScreen<TScreen, TParam> : ActivatableViewModelBase
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called before navigating away from this screen.
|
||||
/// </summary>
|
||||
/// <param name="args">Navigation arguments containing information about the navigation action.</param>
|
||||
public virtual Task OnClosing(NavigationArguments args)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool RecycleScreen
|
||||
{
|
||||
get => _recycleScreen;
|
||||
protected set => RaiseAndSetIfChanged(ref _recycleScreen, value);
|
||||
}
|
||||
|
||||
#region Overrides of RoutableScreen
|
||||
|
||||
object? IRoutableScreen.InternalScreen => Screen;
|
||||
|
||||
void IRoutableScreen.InternalChangeScreen(object? screen)
|
||||
{
|
||||
if (screen == null)
|
||||
{
|
||||
Screen = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (screen is not TScreen typedScreen)
|
||||
throw new ArtemisRoutingException($"Provided screen is not assignable to {typeof(TScreen).FullName}");
|
||||
Screen = typedScreen;
|
||||
}
|
||||
|
||||
|
||||
async Task IRoutableScreen.InternalOnNavigating(NavigationArguments args, CancellationToken cancellationToken)
|
||||
{
|
||||
Func<object[], TParam> activator = GetParameterActivator();
|
||||
@@ -92,6 +35,7 @@ public abstract class RoutableScreen<TScreen, TParam> : ActivatableViewModelBase
|
||||
throw new ArtemisRoutingException($"Did not retrieve the required amount of parameters, expects {_parameterPropertyCount}, got {args.SegmentParameters.Length}.");
|
||||
|
||||
TParam parameters = activator(args.SegmentParameters);
|
||||
await OnNavigating(args, cancellationToken);
|
||||
await OnNavigating(parameters, args, cancellationToken);
|
||||
}
|
||||
|
||||
@@ -100,8 +44,6 @@ public abstract class RoutableScreen<TScreen, TParam> : ActivatableViewModelBase
|
||||
await OnClosing(args);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Parameter generation
|
||||
|
||||
// ReSharper disable once StaticMemberInGenericType - That's intentional, each kind of TParam should have its own property count
|
||||
@@ -1,87 +0,0 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Artemis.UI.Shared.Routing;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a view model to which routing can take place and which in turn can host another view model.
|
||||
/// </summary>
|
||||
/// <typeparam name="TScreen">The type of view model the screen can host.</typeparam>
|
||||
public abstract class RoutableScreen<TScreen> : ActivatableViewModelBase, IRoutableScreen where TScreen : class
|
||||
{
|
||||
private TScreen? _screen;
|
||||
private bool _recycleScreen = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently active child screen.
|
||||
/// </summary>
|
||||
public TScreen? Screen
|
||||
{
|
||||
get => _screen;
|
||||
private set => RaiseAndSetIfChanged(ref _screen, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool RecycleScreen
|
||||
{
|
||||
get => _recycleScreen;
|
||||
protected set => RaiseAndSetIfChanged(ref _recycleScreen, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called before navigating to this screen.
|
||||
/// </summary>
|
||||
/// <param name="args">Navigation arguments containing information about the navigation action.</param>
|
||||
public virtual Task BeforeNavigating(NavigationArguments args)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called while navigating to this screen.
|
||||
/// </summary>
|
||||
/// <param name="args">Navigation arguments containing information about the navigation action.</param>
|
||||
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
|
||||
public virtual Task OnNavigating(NavigationArguments args, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called before navigating away from this screen.
|
||||
/// </summary>
|
||||
/// <param name="args">Navigation arguments containing information about the navigation action.</param>
|
||||
public virtual Task OnClosing(NavigationArguments args)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
#region Overrides of RoutableScreen
|
||||
|
||||
object? IRoutableScreen.InternalScreen => Screen;
|
||||
|
||||
void IRoutableScreen.InternalChangeScreen(object? screen)
|
||||
{
|
||||
if (screen == null)
|
||||
{
|
||||
Screen = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (screen is not TScreen typedScreen)
|
||||
throw new ArtemisRoutingException($"Screen cannot be hosted, {screen.GetType().Name} is not assignable to {typeof(TScreen).Name}.");
|
||||
Screen = typedScreen;
|
||||
}
|
||||
|
||||
async Task IRoutableScreen.InternalOnNavigating(NavigationArguments args, CancellationToken cancellationToken)
|
||||
{
|
||||
await OnNavigating(args, cancellationToken);
|
||||
}
|
||||
|
||||
async Task IRoutableScreen.InternalOnClosing(NavigationArguments args)
|
||||
{
|
||||
await OnClosing(args);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace Artemis.UI.Shared.Routing;
|
||||
/// Represents a registration for a route and its associated view model.
|
||||
/// </summary>
|
||||
/// <typeparam name="TViewModel">The type of the view model associated with the route.</typeparam>
|
||||
public class RouteRegistration<TViewModel> : IRouterRegistration where TViewModel : ViewModelBase
|
||||
public class RouteRegistration<TViewModel> : IRouterRegistration where TViewModel : RoutableScreen
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RouteRegistration{TViewModel}" /> class.
|
||||
|
||||
@@ -74,19 +74,12 @@ internal class RouteResolution
|
||||
};
|
||||
}
|
||||
|
||||
public object GetViewModel(IContainer container)
|
||||
public RoutableScreen GetViewModel(IContainer container)
|
||||
{
|
||||
if (ViewModel == null)
|
||||
throw new ArtemisRoutingException("Cannot get a view model of a non-success route resolution");
|
||||
|
||||
object? viewModel = container.Resolve(ViewModel);
|
||||
if (viewModel == null)
|
||||
throw new ArtemisRoutingException($"Could not resolve view model of type {ViewModel}");
|
||||
|
||||
return viewModel;
|
||||
return GetViewModel<RoutableScreen>(container);
|
||||
}
|
||||
|
||||
public T GetViewModel<T>(IContainer container)
|
||||
public T GetViewModel<T>(IContainer container) where T : RoutableScreen
|
||||
{
|
||||
if (ViewModel == null)
|
||||
throw new ArtemisRoutingException("Cannot get a view model of a non-success route resolution");
|
||||
|
||||
@@ -50,7 +50,7 @@ public interface IRouter
|
||||
/// </summary>
|
||||
/// <param name="root">The root screen to set.</param>
|
||||
/// <typeparam name="TScreen">The type of the root screen. It must be a class.</typeparam>
|
||||
void SetRoot<TScreen>(RoutableScreen<TScreen> root) where TScreen : class;
|
||||
void SetRoot<TScreen>(RoutableHostScreen<TScreen> root) where TScreen : RoutableScreen;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the root screen from which navigation takes place.
|
||||
@@ -58,7 +58,7 @@ public interface IRouter
|
||||
/// <param name="root">The root screen to set.</param>
|
||||
/// <typeparam name="TScreen">The type of the root screen. It must be a class.</typeparam>
|
||||
/// <typeparam name="TParam">The type of the parameters for the root screen. It must have a parameterless constructor.</typeparam>
|
||||
void SetRoot<TScreen, TParam>(RoutableScreen<TScreen, TParam> root) where TScreen : class where TParam : new();
|
||||
void SetRoot<TScreen, TParam>(RoutableHostScreen<TScreen, TParam> root) where TScreen : RoutableScreen where TParam : new();
|
||||
|
||||
/// <summary>
|
||||
/// Clears the route used by the previous window, so that it is not restored when the main window opens.
|
||||
|
||||
@@ -14,12 +14,12 @@ internal class Navigation
|
||||
private readonly IContainer _container;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IRoutableScreen _root;
|
||||
private readonly IRoutableHostScreen _root;
|
||||
private readonly RouteResolution _resolution;
|
||||
private readonly RouterNavigationOptions _options;
|
||||
private CancellationTokenSource _cts;
|
||||
|
||||
public Navigation(IContainer container, ILogger logger, IRoutableScreen root, RouteResolution resolution, RouterNavigationOptions options)
|
||||
public Navigation(IContainer container, ILogger logger, IRoutableHostScreen root, RouteResolution resolution, RouterNavigationOptions options)
|
||||
{
|
||||
_container = container;
|
||||
_logger = logger;
|
||||
@@ -54,21 +54,21 @@ internal class Navigation
|
||||
_cts.Cancel();
|
||||
}
|
||||
|
||||
private async Task NavigateResolution(RouteResolution resolution, NavigationArguments args, IRoutableScreen host)
|
||||
private async Task NavigateResolution(RouteResolution resolution, NavigationArguments args, IRoutableHostScreen host)
|
||||
{
|
||||
if (Cancelled)
|
||||
return;
|
||||
|
||||
// Reuse the screen if its type has not changed, if a new one must be created, don't do so on the UI thread
|
||||
object screen;
|
||||
IRoutableScreen screen;
|
||||
if (_options.RecycleScreens && host.RecycleScreen && host.InternalScreen != null && host.InternalScreen.GetType() == resolution.ViewModel)
|
||||
screen = host.InternalScreen;
|
||||
else
|
||||
screen = await Task.Run(() => resolution.GetViewModel(_container));
|
||||
|
||||
// If resolution has a child, ensure the screen can host it
|
||||
if (resolution.Child != null && screen is not IRoutableScreen)
|
||||
throw new ArtemisRoutingException($"Route resolved with a child but view model of type {resolution.ViewModel} is does mot implement {nameof(IRoutableScreen)}.");
|
||||
if (resolution.Child != null && screen is not IRoutableHostScreen)
|
||||
throw new ArtemisRoutingException($"Route resolved with a child but view model of type {resolution.ViewModel} is does mot implement {nameof(IRoutableHostScreen)}.");
|
||||
|
||||
// Only change the screen if it wasn't reused
|
||||
if (!ReferenceEquals(host.InternalScreen, screen))
|
||||
@@ -87,27 +87,24 @@ internal class Navigation
|
||||
|
||||
if (CancelIfRequested(args, "ChangeScreen", screen))
|
||||
return;
|
||||
|
||||
// If the screen implements some form of Navigable, activate it
|
||||
|
||||
// Navigate on the screen
|
||||
args.SegmentParameters = resolution.Parameters ?? Array.Empty<object>();
|
||||
if (screen is IRoutableScreen routableScreen)
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
await routableScreen.InternalOnNavigating(args, _cts.Token);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Cancel();
|
||||
if (e is not TaskCanceledException)
|
||||
_logger.Error(e, "Failed to navigate to {Path}", resolution.Path);
|
||||
}
|
||||
|
||||
if (CancelIfRequested(args, "OnNavigating", screen))
|
||||
return;
|
||||
await screen.InternalOnNavigating(args, _cts.Token);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Cancel();
|
||||
if (e is not TaskCanceledException)
|
||||
_logger.Error(e, "Failed to navigate to {Path}", resolution.Path);
|
||||
}
|
||||
|
||||
if (screen is IRoutableScreen childScreen)
|
||||
if (CancelIfRequested(args, "OnNavigating", screen))
|
||||
return;
|
||||
|
||||
if (screen is IRoutableHostScreen childScreen)
|
||||
{
|
||||
// Navigate the child too
|
||||
if (resolution.Child != null)
|
||||
|
||||
@@ -14,15 +14,15 @@ internal class Router : CorePropertyChanged, IRouter, IDisposable
|
||||
private readonly Stack<string> _backStack = new();
|
||||
private readonly BehaviorSubject<string?> _currentRouteSubject;
|
||||
private readonly Stack<string> _forwardStack = new();
|
||||
private readonly Func<IRoutableScreen, RouteResolution, RouterNavigationOptions, Navigation> _getNavigation;
|
||||
private readonly Func<IRoutableHostScreen, RouteResolution, RouterNavigationOptions, Navigation> _getNavigation;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMainWindowService _mainWindowService;
|
||||
private Navigation? _currentNavigation;
|
||||
|
||||
private IRoutableScreen? _root;
|
||||
private IRoutableHostScreen? _root;
|
||||
private string? _previousWindowRoute;
|
||||
|
||||
public Router(ILogger logger, IMainWindowService mainWindowService, Func<IRoutableScreen, RouteResolution, RouterNavigationOptions, Navigation> getNavigation)
|
||||
public Router(ILogger logger, IMainWindowService mainWindowService, Func<IRoutableHostScreen, RouteResolution, RouterNavigationOptions, Navigation> getNavigation)
|
||||
{
|
||||
_logger = logger;
|
||||
_mainWindowService = mainWindowService;
|
||||
@@ -45,21 +45,17 @@ internal class Router : CorePropertyChanged, IRouter, IDisposable
|
||||
return RouteResolution.AsFailure(path);
|
||||
}
|
||||
|
||||
private async Task<bool> RequestClose(object screen, NavigationArguments args)
|
||||
private async Task<bool> RequestClose(IRoutableScreen screen, NavigationArguments args)
|
||||
{
|
||||
if (screen is not IRoutableScreen routableScreen)
|
||||
return true;
|
||||
|
||||
await routableScreen.InternalOnClosing(args);
|
||||
if (args.Cancelled)
|
||||
{
|
||||
_logger.Debug("Navigation to {Path} cancelled during RequestClose by {Screen}", args.Path, screen.GetType().Name);
|
||||
// Drill down to child screens first
|
||||
if (screen is IRoutableHostScreen hostScreen && hostScreen.InternalScreen != null && !await RequestClose(hostScreen.InternalScreen, args))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (routableScreen.InternalScreen == null)
|
||||
await screen.InternalOnClosing(args);
|
||||
if (!args.Cancelled)
|
||||
return true;
|
||||
return await RequestClose(routableScreen.InternalScreen, args);
|
||||
_logger.Debug("Navigation to {Path} cancelled during RequestClose by {Screen}", args.Path, screen.GetType().Name);
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool PathEquals(string path, bool allowPartialMatch)
|
||||
@@ -161,13 +157,13 @@ internal class Router : CorePropertyChanged, IRouter, IDisposable
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetRoot<TScreen>(RoutableScreen<TScreen> root) where TScreen : class
|
||||
public void SetRoot<TScreen>(RoutableHostScreen<TScreen> root) where TScreen : RoutableScreen
|
||||
{
|
||||
_root = root;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetRoot<TScreen, TParam>(RoutableScreen<TScreen, TParam> root) where TScreen : class where TParam : new()
|
||||
public void SetRoot<TScreen, TParam>(RoutableHostScreen<TScreen, TParam> root) where TScreen : RoutableScreen where TParam : new()
|
||||
{
|
||||
_root = root;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user