feat: Refactoring and tidy up
This commit is contained in:
Родитель
06be83a535
Коммит
1df398b7b8
|
@ -26,7 +26,7 @@ public sealed partial class App : Application
|
|||
|
||||
var appBuilder = this.CreateBuilder(args)
|
||||
.ConfigureApp()
|
||||
.AddToolkitNavigation();
|
||||
.UseToolkitNavigation();
|
||||
_window = appBuilder.Window;
|
||||
#if NET5_0_OR_GREATER && WINDOWS
|
||||
_window.Activate();
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
{
|
||||
"solution": {
|
||||
"path": "Uno.Extensions.sln",
|
||||
"projects": [
|
||||
"Uno.Extensions.Authentication.MSAL\\Uno.Extensions.Authentication.MSAL.UI.Wasm.csproj",
|
||||
"Uno.Extensions.Authentication.MSAL\\Uno.Extensions.Authentication.MSAL.UI.csproj",
|
||||
"Uno.Extensions.Authentication.MSAL\\Uno.Extensions.Authentication.MSAL.WinUI.Wasm.csproj",
|
||||
"Uno.Extensions.Authentication.MSAL\\Uno.Extensions.Authentication.MSAL.WinUI.csproj",
|
||||
"Uno.Extensions.Authentication.Oidc\\Uno.Extensions.Authentication.Oidc.UI.csproj",
|
||||
"Uno.Extensions.Authentication.Oidc\\Uno.Extensions.Authentication.Oidc.WinUI.csproj",
|
||||
"Uno.Extensions.Authentication.UI\\Uno.Extensions.Authentication.UI.csproj",
|
||||
"Uno.Extensions.Authentication.UI\\Uno.Extensions.Authentication.WinUI.csproj",
|
||||
"Uno.Extensions.Authentication\\Uno.Extensions.Authentication.csproj",
|
||||
"Uno.Extensions.Configuration\\Uno.Extensions.Configuration.csproj",
|
||||
"Uno.Extensions.Core.Generators\\Uno.Extensions.Core.Generators.csproj",
|
||||
"Uno.Extensions.Core\\Uno.Extensions.Core.csproj",
|
||||
"Uno.Extensions.Hosting.UI\\Uno.Extensions.Hosting.UWP.Skia.csproj",
|
||||
"Uno.Extensions.Hosting.UI\\Uno.Extensions.Hosting.UWP.Wasm.csproj",
|
||||
"Uno.Extensions.Hosting.UI\\Uno.Extensions.Hosting.UWP.csproj",
|
||||
"Uno.Extensions.Hosting.UI\\Uno.Extensions.Hosting.WinUI.Skia.csproj",
|
||||
"Uno.Extensions.Hosting.UI\\Uno.Extensions.Hosting.WinUI.Wasm.csproj",
|
||||
"Uno.Extensions.Hosting.UI\\Uno.Extensions.Hosting.WinUI.csproj",
|
||||
"Uno.Extensions.Hosting\\Uno.Extensions.Hosting.csproj",
|
||||
"Uno.Extensions.Http.Refit\\Uno.Extensions.Http.Refit.csproj",
|
||||
"Uno.Extensions.Http.Tests\\Uno.Extensions.Http.Tests.csproj",
|
||||
"Uno.Extensions.Http\\Uno.Extensions.Http.csproj",
|
||||
"Uno.Extensions.Localization.UI\\Uno.Extensions.Localization.UI.csproj",
|
||||
"Uno.Extensions.Localization.UI\\Uno.Extensions.Localization.WinUI.csproj",
|
||||
"Uno.Extensions.Localization\\Uno.Extensions.Localization.csproj",
|
||||
"Uno.Extensions.Logging.Serilog\\Uno.Extensions.Logging.Serilog.csproj",
|
||||
"Uno.Extensions.Logging\\Uno.Extensions.Logging.UWP.Skia.csproj",
|
||||
"Uno.Extensions.Logging\\Uno.Extensions.Logging.UWP.Wasm.csproj",
|
||||
"Uno.Extensions.Logging\\Uno.Extensions.Logging.UWP.csproj",
|
||||
"Uno.Extensions.Logging\\Uno.Extensions.Logging.WinUI.Skia.csproj",
|
||||
"Uno.Extensions.Logging\\Uno.Extensions.Logging.WinUI.Wasm.csproj",
|
||||
"Uno.Extensions.Logging\\Uno.Extensions.Logging.WinUI.csproj",
|
||||
"Uno.Extensions.Navigation.Toolkit\\Uno.Extensions.Navigation.Toolkit.UI.csproj",
|
||||
"Uno.Extensions.Navigation.Toolkit\\Uno.Extensions.Navigation.Toolkit.WinUI.csproj",
|
||||
"Uno.Extensions.Navigation.UI\\Uno.Extensions.Navigation.UI.csproj",
|
||||
"Uno.Extensions.Navigation.UI\\Uno.Extensions.Navigation.WinUI.csproj",
|
||||
"Uno.Extensions.Navigation.WinUI.Markup\\Uno.Extensions.Navigation.WinUI.Markup.csproj",
|
||||
"Uno.Extensions.Navigation\\Uno.Extensions.Navigation.csproj",
|
||||
"Uno.Extensions.Reactive.Generator\\Uno.Extensions.Reactive.Generator.csproj",
|
||||
"Uno.Extensions.Reactive.Messaging\\Uno.Extensions.Reactive.Messaging.csproj",
|
||||
"Uno.Extensions.Reactive.UI\\Uno.Extensions.Reactive.UI.WinUI.csproj",
|
||||
"Uno.Extensions.Reactive.UI\\Uno.Extensions.Reactive.UI.csproj",
|
||||
"Uno.Extensions.Reactive.WinUI.Markup\\Uno.Extensions.Reactive.WinUI.Markup.csproj",
|
||||
"Uno.Extensions.Reactive\\Uno.Extensions.Reactive.csproj",
|
||||
"Uno.Extensions.Serialization.Http\\Uno.Extensions.Serialization.Http.csproj",
|
||||
"Uno.Extensions.Serialization.Refit\\Uno.Extensions.Serialization.Refit.csproj",
|
||||
"Uno.Extensions.Serialization\\Uno.Extensions.Serialization.csproj",
|
||||
"Uno.Extensions.Storage.UI\\Uno.Extensions.Storage.UI.csproj",
|
||||
"Uno.Extensions.Storage.UI\\Uno.Extensions.Storage.WinUI.csproj",
|
||||
"Uno.Extensions.Storage\\Uno.Extensions.Storage.csproj",
|
||||
"Uno.Extensions.Templates\\Uno.Extensions.Templates.csproj",
|
||||
"Uno.Extensions\\Uno.Extensions.csproj"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
namespace Uno.Extensions;
|
||||
|
||||
public static class ApplicationBuilderExtensions
|
||||
{
|
||||
private struct ToolkitViewInitializer : IRootViewInitializer
|
||||
{
|
||||
public ContentControl CreateDefaultView() => new LoadingView();
|
||||
|
||||
public void InitializeViewHost(FrameworkElement element, Task loadingTask)
|
||||
{
|
||||
if (element is LoadingView loadingView)
|
||||
{
|
||||
loadingView.Source = new LoadingTask(loadingTask, element);
|
||||
}
|
||||
}
|
||||
|
||||
public void PreInitialize(FrameworkElement element, IApplicationBuilder builder)
|
||||
{
|
||||
if (element is ExtendedSplashScreen splash)
|
||||
{
|
||||
splash.Initialize(builder.Window, builder.Arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IApplicationBuilder UseToolkitNavigation(this IApplicationBuilder builder)
|
||||
{
|
||||
builder.Properties.Add(typeof(IRootViewInitializer), new ToolkitViewInitializer());
|
||||
return builder.Configure(host => host.UseToolkitNavigation());
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ global using Microsoft.Extensions.Hosting;
|
|||
global using Microsoft.Extensions.Logging;
|
||||
global using Windows.Foundation;
|
||||
global using Windows.UI.Popups;
|
||||
global using Uno.Extensions.Hosting;
|
||||
global using Uno.Extensions.Navigation;
|
||||
global using Uno.Extensions.Navigation.Navigators;
|
||||
global using Uno.Extensions.Navigation.Regions;
|
||||
|
|
|
@ -1,40 +1,10 @@
|
|||
using Uno.Extensions.Hosting;
|
||||
|
||||
namespace Uno.Extensions;
|
||||
namespace Uno.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for adding services to an <see cref="IServiceCollection" />.
|
||||
/// </summary>
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
private struct ToolkitViewInitializer : IRootViewInitializer
|
||||
{
|
||||
public ContentControl CreateDefaultView() => new LoadingView();
|
||||
|
||||
public void InitializeViewHost(FrameworkElement element, Task loadingTask)
|
||||
{
|
||||
if (element is LoadingView loadingView)
|
||||
{
|
||||
loadingView.Source = new LoadingTask(loadingTask, element);
|
||||
}
|
||||
}
|
||||
|
||||
public void PreInitialize(FrameworkElement element, IApplicationBuilder builder)
|
||||
{
|
||||
if (element is ExtendedSplashScreen splash)
|
||||
{
|
||||
splash.Initialize(builder.Window, builder.Arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IApplicationBuilder AddToolkitNavigation(this IApplicationBuilder builder)
|
||||
{
|
||||
builder.Properties.Add(typeof(IRootViewInitializer), new ToolkitViewInitializer());
|
||||
return builder.Configure(host => host.ConfigureServices(
|
||||
services => services.AddToolkitNavigation()));
|
||||
}
|
||||
|
||||
private static bool _didRegisterServices;
|
||||
/// <summary>
|
||||
/// Adds navigation support for toolkit controls such as TabBar and DrawControl
|
||||
|
@ -59,41 +29,4 @@ public static class ServiceCollectionExtensions
|
|||
|
||||
.AddSingleton<IRequestHandler, TabBarItemRequestHandler>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes navigation for an application using the LoadingView (from Uno Toolkit) to implement an extended splash screen
|
||||
/// Requires a Style for LoadingView with LoadingContent specified
|
||||
/// </summary>
|
||||
/// <param name="window">The application Window to initialize navigation for</param>
|
||||
/// <param name="buildHost">Function to create IHost</param>
|
||||
/// <param name="navigationRoot">LoadingView to host app navigation (only required for nesting navigation in an existing application)</param>
|
||||
/// <param name="initialRoute">[optional] Initial navigation route</param>
|
||||
/// <param name="initialView">[optional] Initial navigation view</param>
|
||||
/// <param name="initialViewModel">[optional] Initial navigation viewmodel</param>
|
||||
/// <param name="initialNavigate">[optional] Callback to drive initial navigation for app</param>
|
||||
/// <returns>The created IHost</returns>
|
||||
public static Task<IHost> InitializeNavigationAsync(
|
||||
this Window window,
|
||||
Func<Task<IHost>> buildHost,
|
||||
LoadingView navigationRoot,
|
||||
string? initialRoute = "",
|
||||
Type? initialView = null,
|
||||
Type? initialViewModel = null,
|
||||
Func<IServiceProvider, INavigator, Task>? initialNavigate = null)
|
||||
{
|
||||
return window.InternalInitializeNavigationAsync(
|
||||
buildHost,
|
||||
navigationRoot,
|
||||
initialRoute, initialView, initialViewModel,
|
||||
(root, navInit) =>
|
||||
{
|
||||
var loading = new LoadingTask(navInit, root);
|
||||
if (root is LoadingView lv)
|
||||
{
|
||||
lv.Source = loading;
|
||||
}
|
||||
},
|
||||
initialNavigate
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
namespace Uno.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods on <see cref="Window" />.
|
||||
/// </summary>
|
||||
public static class WindowExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes navigation for an application using the LoadingView (from Uno Toolkit) to implement an extended splash screen
|
||||
/// Requires a Style for LoadingView with LoadingContent specified
|
||||
/// </summary>
|
||||
/// <param name="window">The application Window to initialize navigation for</param>
|
||||
/// <param name="buildHost">Function to create IHost</param>
|
||||
/// <param name="navigationRoot">LoadingView to host app navigation (only required for nesting navigation in an existing application)</param>
|
||||
/// <param name="initialRoute">[optional] Initial navigation route</param>
|
||||
/// <param name="initialView">[optional] Initial navigation view</param>
|
||||
/// <param name="initialViewModel">[optional] Initial navigation viewmodel</param>
|
||||
/// <param name="initialNavigate">[optional] Callback to drive initial navigation for app</param>
|
||||
/// <returns>The created IHost</returns>
|
||||
public static Task<IHost> InitializeNavigationAsync(
|
||||
this Window window,
|
||||
Func<Task<IHost>> buildHost,
|
||||
LoadingView navigationRoot,
|
||||
string? initialRoute = "",
|
||||
Type? initialView = null,
|
||||
Type? initialViewModel = null,
|
||||
Func<IServiceProvider, INavigator, Task>? initialNavigate = null)
|
||||
{
|
||||
return window.InternalInitializeNavigationAsync(
|
||||
buildHost,
|
||||
navigationRoot,
|
||||
initialRoute, initialView, initialViewModel,
|
||||
(root, navInit) =>
|
||||
{
|
||||
var loading = new LoadingTask(navInit, root);
|
||||
if (root is LoadingView lv)
|
||||
{
|
||||
lv.Source = loading;
|
||||
}
|
||||
},
|
||||
initialNavigate
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
namespace Uno.Extensions.Navigation;
|
||||
namespace Uno.Extensions;
|
||||
|
||||
public static class ApplicationBuilderExtensions
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Uno.Extensions.Navigation;
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public interface IRootViewInitializer
|
||||
internal interface IRootViewInitializer
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a default navigation root container
|
||||
|
|
|
@ -30,9 +30,7 @@ public sealed partial class App : Application
|
|||
.Localization()
|
||||
.Serialization()
|
||||
.Services()
|
||||
.Navigation()
|
||||
// Add navigation support for toolkit controls such as TabBar and NavigationView
|
||||
.UseToolkitNavigation();;
|
||||
.Navigation();
|
||||
_window = builder.Window;
|
||||
|
||||
_host = await builder.ShowAsync<Shell>();
|
||||
|
|
|
@ -57,13 +57,16 @@ public static class HostConfiguration
|
|||
public static IApplicationBuilder Navigation(this IApplicationBuilder builder)
|
||||
{
|
||||
// Enable navigation, including registering views and viewmodels
|
||||
return builder.Configure(host => host.UseNavigation(
|
||||
return builder
|
||||
.Configure(host => host.UseNavigation(
|
||||
//+:cnd:noEmit
|
||||
#if(reactive)
|
||||
ReactiveViewModelMappings.ViewModelMappings,
|
||||
#endif
|
||||
//-:cnd:noEmit
|
||||
RegisterRoutes));
|
||||
RegisterRoutes))
|
||||
// Add navigation support for toolkit controls such as TabBar and NavigationView
|
||||
.UseToolkitNavigation();
|
||||
}
|
||||
|
||||
private static void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
|
||||
|
|
Загрузка…
Ссылка в новой задаче