diff --git a/Mopups/Mopups.Maui/Platforms/iOS/PopupWindow.cs b/Mopups/Mopups.Maui/Platforms/iOS/PopupWindow.cs index d5ddfa1..e6ffc88 100644 --- a/Mopups/Mopups.Maui/Platforms/iOS/PopupWindow.cs +++ b/Mopups/Mopups.Maui/Platforms/iOS/PopupWindow.cs @@ -24,25 +24,42 @@ public PopupWindow(UIWindowScene uiWindowScene) : base(uiWindowScene) } - public override UIView HitTest(CGPoint point, UIEvent? uievent) + public override UIView? HitTest(CGPoint point, UIEvent? uievent) { - var platformHandler = (PopupPageRenderer?)RootViewController; - var renderer = platformHandler?.Handler; - var hitTestResult = base.HitTest(point, uievent); + try + { + var platformHandler = (PopupPageRenderer?)RootViewController; + var renderer = platformHandler?.Handler; + var hitTestResult = base.HitTest(point, uievent); - if (!(platformHandler?.Handler?.VirtualView is PopupPage formsElement)) - return hitTestResult; + if(renderer?.VirtualView is null) + { + return hitTestResult; + } + + if(renderer.VirtualView is not PopupPage formsElement) + return hitTestResult; - if (formsElement.InputTransparent) - return null!; + if(formsElement.InputTransparent) + return null; - if (formsElement.BackgroundInputTransparent && renderer?.PlatformView == hitTestResult) + if(formsElement.BackgroundInputTransparent && renderer.PlatformView == hitTestResult) + { + formsElement.SendBackgroundClick(); + return null; + } + return hitTestResult; + } + catch(Exception) { - formsElement.SendBackgroundClick(); - return null!; + // Perform any necessary cleanup here + RootViewController?.View?.RemoveFromSuperview(); + RootViewController = null; + Hidden = true; + Dispose(); + + return null; } - return hitTestResult; - } } }