Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ public static MauiAppBuilder ConfigureLicensing(this MauiAppBuilder builder, Uri
builder.Services.AddSingleton<ILicenseManager>(manager);
return builder;
}
public static MauiAppBuilder ConfigureAppUpdater(this MauiAppBuilder builder, ILicenseManager licenseManager, IDispatcher dispatcher)
public static MauiAppBuilder ConfigureAppUpdater(this MauiAppBuilder builder, ILicenseManager licenseManager, IDispatcher? dispatcher = null)
{
dispatcher ??= builder.Services.BuildServiceProvider().GetService<IDispatcher>();
AppUpdateManager manager = new(dispatcher, licenseManager);
builder.Services.AddSingleton<IAppUpdateManager>(manager);
return builder;
}
public static MauiAppBuilder ConfigureAppUpdater(this MauiAppBuilder builder)
public static MauiAppBuilder ConfigureAppUpdater(this MauiAppBuilder builder, IDispatcher? dispatcher = null)
{
ILicenseManager? licenseManager = builder.Services.BuildServiceProvider().GetService<ILicenseManager>();
IDispatcher? dispatcher = builder.Services.BuildServiceProvider().GetService<IDispatcher>();
dispatcher ??= builder.Services.BuildServiceProvider().GetService<IDispatcher>();
if (licenseManager is not null && dispatcher is not null)
{
builder.ConfigureAppUpdater(licenseManager, dispatcher);
Expand Down
10 changes: 10 additions & 0 deletions src/SharedMauiCoreLibrary/Hosting/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AndreasReitberger.Shared.Core.Interfaces;
using AndreasReitberger.Shared.Core.Localization;
using AndreasReitberger.Shared.Core.NavigationManager;
using CommunityToolkit.Maui;
using System.Runtime.Versioning;

Expand Down Expand Up @@ -37,5 +38,14 @@ public static MauiAppBuilder ConfigureLocalizationManager(this MauiAppBuilder bu
builder.Services.AddSingleton<ILocalizationManager>(manager);
return builder;
}

public static MauiAppBuilder ConfigureShellNavigator(this MauiAppBuilder builder, string rootPage, List<string>? entryPages = null, IDispatcher? dispatcher = null)
{
dispatcher ??= builder.Services.BuildServiceProvider().GetService<IDispatcher>();
ShellNavigator navigator = dispatcher is not null ? new(rootPage, dispatcher) : new(rootPage);
navigator.AvailableEntryPages = [.. entryPages ?? [ rootPage]];
builder.Services.AddSingleton<IShellNavigator>(navigator);
return builder;
}
}
}
2 changes: 2 additions & 0 deletions src/SharedMauiCoreLibrary/Interfaces/IShellNavigator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public interface IShellNavigator
public Task<bool> GoToRootAsync(string target, Dictionary<string, object>? parameters = null, bool? flyoutIsPresented = null, int delay = -1, bool animate = false, string rootPrefix = "///");
public Task<bool> GoBackAsync(Dictionary<string, object>? parameters = null, bool? flyoutIsPresented = null, int delay = -1, bool animate = false, bool confirm = false, Func<Task<bool>>? confirmFunction = null);
bool IsCurrentPathRoot();
public void SubscribeNavigated();
public void UnsubscribeNavigated();
#endregion

#region Events
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AndreasReitberger.Shared.Core.Events;
using AndreasReitberger.Shared.Core.Interfaces;
using System.Diagnostics;

namespace AndreasReitberger.Shared.Core.NavigationManager
{
Expand Down Expand Up @@ -58,7 +59,7 @@ public static IShellNavigator Instance
public ShellNavigator()
{
Dispatcher = DispatcherProvider.Current.GetForCurrentThread();
Shell.Current.Navigated += (a, b) =>
Shell.Current?.Navigated += (a, b) =>
{
string msg = $"Navigation: From '{b.Previous?.Location}' to '{b.Current?.Location}'. Source = '{b.Source}'";
OnNavigationDone(new NavigationDoneEventArgs()
Expand Down Expand Up @@ -221,7 +222,36 @@ string GetCurrentRoute()
return string.Empty;
}
}
public void SubscribeNavigated()
{
if (Shell.Current is not null)
{
UnsubscribeNavigated();
Shell.Current.Navigated += OnNavigated;
}
}
public void UnsubscribeNavigated()
{
if (Shell.Current is not null)
{
Shell.Current.Navigated -= OnNavigated;
}
}

private void OnNavigated(object? sender, ShellNavigatedEventArgs e)
{
#if DEBUG
string msg = $"Navigation: From '{e.Previous?.Location}' to '{e.Current?.Location}'. Source = '{e.Source}'";
Debug.WriteLine(msg);
#endif
OnNavigationDone(new NavigationDoneEventArgs()
{
Arguments = e,
NavigatedFrom = e.Previous?.Location,
NavigatedTo = e.Current?.Location,
Source = e.Source,
});
}
#endregion

}
Expand Down
Loading