diff --git a/samples/MauiEmbedding/Directory.Build.props b/samples/MauiEmbedding/Directory.Build.props index 9428bd358b..0915308f4f 100644 --- a/samples/MauiEmbedding/Directory.Build.props +++ b/samples/MauiEmbedding/Directory.Build.props @@ -1,4 +1,6 @@ + + enable enable diff --git a/samples/MauiEmbedding/Directory.Packages.props b/samples/MauiEmbedding/Directory.Packages.props index 7c2df978ee..2834fb8e51 100644 --- a/samples/MauiEmbedding/Directory.Packages.props +++ b/samples/MauiEmbedding/Directory.Packages.props @@ -1,13 +1,13 @@ - + - - - - - + + + + + @@ -15,18 +15,17 @@ - + - - - - + + + - - - + + + diff --git a/samples/MauiEmbedding/MauiEmbedding.MauiControls/CustomEntry.cs b/samples/MauiEmbedding/MauiEmbedding.MauiControls/CustomEntry.cs index f8047d4f8d..b27c974e95 100644 --- a/samples/MauiEmbedding/MauiEmbedding.MauiControls/CustomEntry.cs +++ b/samples/MauiEmbedding/MauiEmbedding.MauiControls/CustomEntry.cs @@ -24,7 +24,7 @@ internal static void Init() return; } -#if IOS +#if IOS || MACCATALYST if (h.PlatformView is UIKit.UITextField textField) { var color = entry.BorderColor?.ToPlatform().CGColor ?? UIKit.UIColor.Black.CGColor; diff --git a/samples/MauiEmbedding/MauiEmbedding.MauiControls/MauiEmbedding.MauiControls.csproj b/samples/MauiEmbedding/MauiEmbedding.MauiControls/MauiEmbedding.MauiControls.csproj index 23065f29cc..4f0f0f3974 100644 --- a/samples/MauiEmbedding/MauiEmbedding.MauiControls/MauiEmbedding.MauiControls.csproj +++ b/samples/MauiEmbedding/MauiEmbedding.MauiControls/MauiEmbedding.MauiControls.csproj @@ -1,4 +1,4 @@ - + net8.0;net8.0-android;net8.0-ios;net8.0-maccatalyst diff --git a/samples/MauiEmbedding/MauiEmbedding.Mobile/MauiEmbedding.Mobile.csproj b/samples/MauiEmbedding/MauiEmbedding.Mobile/MauiEmbedding.Mobile.csproj index d9314982e3..95421c1e30 100644 --- a/samples/MauiEmbedding/MauiEmbedding.Mobile/MauiEmbedding.Mobile.csproj +++ b/samples/MauiEmbedding/MauiEmbedding.Mobile/MauiEmbedding.Mobile.csproj @@ -1,4 +1,4 @@ - + @@ -37,7 +37,6 @@ - diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index 2038590fbc..6f09e2b82e 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -1,4 +1,15 @@ + + + 5.0.19 + 5.2.22 + 1.4.231219000 + + + @@ -14,7 +25,7 @@ - + @@ -23,7 +34,7 @@ - + @@ -48,15 +59,15 @@ - - - - + + + + - + - - + + diff --git a/src/Uno.Extensions.Hosting.UI/ApplicationBuilder.cs b/src/Uno.Extensions.Hosting.UI/ApplicationBuilder.cs index 19facf6269..92d0dbc5b4 100644 --- a/src/Uno.Extensions.Hosting.UI/ApplicationBuilder.cs +++ b/src/Uno.Extensions.Hosting.UI/ApplicationBuilder.cs @@ -1,4 +1,4 @@ -namespace Uno.Extensions.Hosting; +namespace Uno.Extensions.Hosting; internal record ApplicationBuilder(Application App, LaunchActivatedEventArgs Arguments, Assembly ApplicationAssembly) : IApplicationBuilder { @@ -9,6 +9,10 @@ internal record ApplicationBuilder(Application App, LaunchActivatedEventArgs Arg public Window Window { get; } = #if NET6_0_OR_GREATER && WINDOWS && !HAS_UNO new Window(); +#elif HAS_UNO_WINUI + // Window.Current can be null with Uno.WinUI 5.2+ + // When updating Hosting to Uno.WinUI 5.2+ we need to remove the compiler directive + Window.Current ?? new Window(); #else Window.Current; #endif diff --git a/src/Uno.Extensions.Maui.UI/MauiEmbedding.apple.cs b/src/Uno.Extensions.Maui.UI/MauiEmbedding.apple.cs index 260526e2e8..1edbbf42be 100644 --- a/src/Uno.Extensions.Maui.UI/MauiEmbedding.apple.cs +++ b/src/Uno.Extensions.Maui.UI/MauiEmbedding.apple.cs @@ -2,43 +2,37 @@ using Uno.Extensions.Maui.Platform; using Microsoft.Maui; using Windows.UI.Core; +using Uno.UI.Xaml; namespace Uno.Extensions.Maui; partial class MauiEmbedding { - // NOTE: This is meant to help initialize MauiEmbedding similar to MauiUIApplicationDelegate - // https://github.com/dotnet/maui/blob/ace9fe5e7d8d9bd16a2ae0b2fe2b888ad681433e/src/Core/src/Platform/iOS/MauiUIApplicationDelegate.cs#L36-L70 - private static MauiAppBuilder RegisterPlatformServices(this MauiAppBuilder builder, Application app) - { - builder.Services.AddSingleton(sp => - { - var window = sp.GetRequiredService(); - // The _window field is the only way to grab the underlying UIWindow from inside the CoreWindow - // https://github.com/unoplatform/uno/blob/34a32058b812a0a08e658eba5e298ea9d258c231/src/Uno.UWP/UI/Core/CoreWindow.iOS.cs#L17 - var internalWindow = typeof(CoreWindow).GetField("_window", BindingFlags.Instance | BindingFlags.NonPublic); - if(internalWindow is null) - { - throw new MauiEmbeddingException(Properties.Resources.MissingWindowPrivateField); - } - var uiwindow = internalWindow?.GetValue(window.CoreWindow) as UIWindow; - return uiwindow!; - }) - .AddSingleton(sp => sp.GetRequiredService()); + // NOTE: This is meant to help initialize MauiEmbedding similar to MauiUIApplicationDelegate + // https://github.com/dotnet/maui/blob/ace9fe5e7d8d9bd16a2ae0b2fe2b888ad681433e/src/Core/src/Platform/iOS/MauiUIApplicationDelegate.cs#L36-L70 + private static MauiAppBuilder RegisterPlatformServices(this MauiAppBuilder builder, Application app) + { + builder.Services.AddTransient(sp => + { + var window = sp.GetRequiredService(); + var nativeWindow = WindowHelper.GetNativeWindow(window); + return nativeWindow is UIWindow uiWindow ? uiWindow : throw new InvalidOperationException("Unable to locate the Native UIWindow"); + }) + .AddSingleton(sp => sp.GetRequiredService()); - return builder; - } + return builder; + } - private static void InitializeMauiEmbeddingApp(this MauiApp mauiApp, Application app) - { - var rootContext = new MauiContext(mauiApp.Services); - rootContext.InitializeScopedServices(); + private static void InitializeMauiEmbeddingApp(this MauiApp mauiApp, Application app) + { + var rootContext = new MauiContext(mauiApp.Services); + rootContext.InitializeScopedServices(); - var iApp = mauiApp.Services.GetRequiredService(); + var iApp = mauiApp.Services.GetRequiredService(); - Microsoft.Maui.ApplicationModel.Platform.Init(() => mauiApp.Services.GetRequiredService().RootViewController!); - _ = new EmbeddedApplication(mauiApp.Services, iApp); - app.SetApplicationHandler(iApp, rootContext); - InitializeApplicationMainPage(iApp); - } + Microsoft.Maui.ApplicationModel.Platform.Init(() => mauiApp.Services.GetRequiredService().RootViewController!); + _ = new EmbeddedApplication(mauiApp.Services, iApp); + app.SetApplicationHandler(iApp, rootContext); + InitializeApplicationMainPage(iApp); + } } diff --git a/src/Uno.Extensions.Navigation.UI/Navigators/ContentDialogNavigator.cs b/src/Uno.Extensions.Navigation.UI/Navigators/ContentDialogNavigator.cs index 67a65d256d..8c3878c2b6 100644 --- a/src/Uno.Extensions.Navigation.UI/Navigators/ContentDialogNavigator.cs +++ b/src/Uno.Extensions.Navigation.UI/Navigators/ContentDialogNavigator.cs @@ -51,7 +51,8 @@ services is null || } #if WINUI - dialog.XamlRoot = Window!.Content.XamlRoot; + // NOTE: We needed to add the ! operator on Content due to a nullability issue starting in Uno.WinUI 5.2 + dialog.XamlRoot = Window!.Content!.XamlRoot; #endif dialog.SetInstance(Region); diff --git a/src/Uno.Extensions.Navigation.UI/ServiceProviderExtensions.cs b/src/Uno.Extensions.Navigation.UI/ServiceProviderExtensions.cs index 064bf6b507..0e739d9efc 100644 --- a/src/Uno.Extensions.Navigation.UI/ServiceProviderExtensions.cs +++ b/src/Uno.Extensions.Navigation.UI/ServiceProviderExtensions.cs @@ -10,7 +10,8 @@ public static class ServiceProviderExtensions /// The IServiceProvider instance to attach public async static Task AttachServicesAsync(this Window window, IServiceProvider services) { - return await window.Content + // NOTE: This creates a nullable error in Uno.WinUI 5.2+ + return await window.Content! .AttachServiceProvider(services) .RegisterWindowAsync(window); } diff --git a/src/maui-embedding.props b/src/maui-embedding.props new file mode 100644 index 0000000000..1ffd11f373 --- /dev/null +++ b/src/maui-embedding.props @@ -0,0 +1,6 @@ + + + 5.2.22 + 1.5.240404000 + + diff --git a/testing/TestHarness/Directory.Packages.props b/testing/TestHarness/Directory.Packages.props index c58edf7d0c..2a54f1e22e 100644 --- a/testing/TestHarness/Directory.Packages.props +++ b/testing/TestHarness/Directory.Packages.props @@ -11,7 +11,7 @@ - +