Skip to content

Commit

Permalink
chore: Fixing reference to UIWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrandolph committed Apr 10, 2024
1 parent 454b9d4 commit 4b802eb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
10 changes: 5 additions & 5 deletions samples/MauiEmbedding/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
<PackageVersion Include="Uno.Toolkit.WinUI" Version="5.0.15" />
<PackageVersion Include="Uno.Toolkit.WinUI.Material" Version="5.0.15" />
<PackageVersion Include="Uno.Resizetizer" Version="1.2.0" />
<PackageVersion Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" Version="5.0.19" />
<PackageVersion Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" Version="5.2.22" />
<PackageVersion Include="Uno.UniversalImageLoader" Version="1.9.36" />
<PackageVersion Include="Uno.WinUI" Version="5.0.19" />
<PackageVersion Include="Uno.WinUI.Skia.Gtk" Version="5.0.19" />
<PackageVersion Include="Uno.WinUI.RemoteControl" Version="5.0.19" />
<PackageVersion Include="Uno.WinUI" Version="5.2.22" />
<PackageVersion Include="Uno.WinUI.Skia.Gtk" Version="5.2.22" />
<PackageVersion Include="Uno.WinUI.RemoteControl" Version="5.2.22" />
<PackageVersion Include="CommunityToolkit.Maui" Version="2.0.0" />
<PackageVersion Include="Telerik.UI.for.Maui" Version="5.1.0" Condition="$(_UseTelerik)" />
<PackageVersion Include="Esri.ArcGISRuntime.Maui" Version="200.1.0" />
<PackageVersion Include="Microsoft.Windows.Compatibility" Version="7.0.4" />
<PackageVersion Include="Uno.Extensions.Logging.WebAssembly.Console" Version="1.7.0" />
<PackageVersion Include="Uno.WinUI.WebAssembly" Version="5.0.19" />
<PackageVersion Include="Uno.WinUI.WebAssembly" Version="5.2.22" />
<PackageVersion Include="Uno.Wasm.Bootstrap" Version="8.0.7" />
<PackageVersion Include="Uno.Wasm.Bootstrap.DevServer" Version="8.0.7" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<UnoDisableHotRestartHelperGeneration>false</UnoDisableHotRestartHelperGeneration>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)'=='net8.0-ios'">
<CodesignKey>Apple Development: Nick Randolph (UWH57C8LKA)</CodesignKey>
<CodesignProvision>VS: WildCard Development</CodesignProvision>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Uno.WinUI" />
<PackageReference Include="CommunityToolkit.Mvvm" />
Expand All @@ -36,7 +41,7 @@
<PackageReference Include="Uno.Toolkit.WinUI" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
<PackageReference Include="Uno.Extensions.Logging.OSLog" />
<PackageReference Include="Telerik.UI.for.Maui" Condition="$(_UseTelerik)"/>
<PackageReference Include="Telerik.UI.for.Maui" Condition="$(_UseTelerik)" />
<PackageReference Include="CommunityToolkit.Maui" />
<PackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" />
<!--<PackageReference Include="Uno.WinUI.RemoteControl" Condition="'$(Configuration)'=='Debug'" />-->
Expand Down
5 changes: 4 additions & 1 deletion samples/MauiEmbedding/MauiEmbedding/MauiEmbedding.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
<ItemGroup>
<PackageReference Include="Uno.Dsp.Tasks" />
<PackageReference Include="Uno.WinUI" />
<PackageReference Include="Uno.Resizetizer" />
<PackageReference Include="Uno.Resizetizer">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CommunityToolkit.Mvvm" />
<PackageReference Include="Uno.Material.WinUI" />
<PackageReference Include="Uno.Toolkit.WinUI.Material" />
Expand Down
13 changes: 10 additions & 3 deletions src/Uno.Extensions.Maui.UI/MauiEmbedding.apple.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using UIKit;
using Uno.Extensions.Maui.Platform;
using Microsoft.Maui;
using UIKit;
using Windows.UI.Core;

namespace Uno.Extensions.Maui;
Expand All @@ -14,10 +13,18 @@ private static MauiAppBuilder RegisterPlatformServices(this MauiAppBuilder build
builder.Services.AddSingleton<UIWindow>(sp =>
{
var window = sp.GetRequiredService<Microsoft.UI.Xaml.Window>();

var nativeWindowProp = window.GetType().GetProperty("NativeWindow", BindingFlags.Instance | BindingFlags.NonPublic);
if (nativeWindowProp is not null)
{
var nativeWindow = nativeWindowProp.GetValue(window) as UIWindow;
return nativeWindow!;
}

// 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)
if (internalWindow is null)
{
throw new MauiEmbeddingException(Properties.Resources.MissingWindowPrivateField);
}
Expand Down

0 comments on commit 4b802eb

Please sign in to comment.