Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
MartyIX committed Aug 14, 2024
1 parent 9d98c28 commit 251d4fa
Showing 2 changed files with 31 additions and 14 deletions.
43 changes: 30 additions & 13 deletions src/Core/src/Handlers/Window/WindowHandler.iOS.cs
Original file line number Diff line number Diff line change
@@ -6,32 +6,22 @@ namespace Microsoft.Maui.Handlers
{
public partial class WindowHandler : ElementHandler<IWindow, UIWindow>
{
private IDisposable? _effectiveGeometryObserver;
readonly WindowProxy _proxy = new();

protected override void ConnectHandler(UIWindow platformView)
{
base.ConnectHandler(platformView);

UpdateVirtualViewFrame(platformView);

_effectiveGeometryObserver = platformView.WindowScene?.AddObserver("effectiveGeometry", NSKeyValueObservingOptions.OldNew, HandleEffectiveGeometryObserved);
_proxy.Connect(VirtualView, platformView);
}

protected override void DisconnectHandler(UIWindow platformView)
{
_effectiveGeometryObserver?.Dispose();

_proxy.Disconnect();
base.DisconnectHandler(platformView);
}

void HandleEffectiveGeometryObserved(NSObservedChange obj)
{
if (obj is not null && obj.NewValue is UIWindowSceneGeometry newGeometry)
{
VirtualView.FrameChanged(newGeometry.SystemFrame.ToRectangle());
}
}

public static void MapTitle(IWindowHandler handler, IWindow window) =>
handler.PlatformView.UpdateTitle(window);

@@ -110,5 +100,32 @@ void UpdateVirtualViewFrame(UIWindow window)
{
VirtualView.FrameChanged(window.Bounds.ToRectangle());
}

class WindowProxy
{
WeakReference<IWindow>? _virtualView;

IWindow? VirtualView => _virtualView is not null && _virtualView.TryGetTarget(out var v) ? v : null;
IDisposable? _effectiveGeometryObserver;

public void Connect(IWindow virtualView, UIWindow platformView)
{
_virtualView = new(virtualView);
_effectiveGeometryObserver = platformView.WindowScene?.AddObserver("effectiveGeometry", NSKeyValueObservingOptions.OldNew, HandleEffectiveGeometryObserved);
}

public void Disconnect()
{
_effectiveGeometryObserver?.Dispose();
}

void HandleEffectiveGeometryObserved(NSObservedChange obj)
{
if (obj is not null && VirtualView is IWindow virtualView && obj.NewValue is UIWindowSceneGeometry newGeometry)
{
virtualView.FrameChanged(newGeometry.SystemFrame.ToRectangle());
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Core/src/Platform/iOS/WindowExtensions.cs
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ internal static void UpdateHeight(this UIWindow platformWindow, IWindow window)

internal static void UpdateCoordinates(this UIWindow platformWindow, IWindow window)
{
if (OperatingSystem.IsIOSVersionAtLeast(16) && platformWindow.WindowScene is {} windowScene))
if (OperatingSystem.IsIOSVersionAtLeast(16) && platformWindow.WindowScene is {} windowScene)
{
var preferences = new UIWindowSceneGeometryPreferencesMac()
{

0 comments on commit 251d4fa

Please sign in to comment.