From a64a99db191b0432e41b9ce5cd8aba61d5e10038 Mon Sep 17 00:00:00 2001 From: microspaze Date: Tue, 2 Apr 2024 15:56:12 +0800 Subject: [PATCH] Fix The specified child already has a parent. You must call removeView() on the child's parent first. #6 --- RGPopup.Maui/Platforms/Android/Impl/PopupPlatformDroid.cs | 5 +++-- .../Platforms/MacCatalyst/Impl/PopupPlatformMacOS.cs | 1 + RGPopup.Maui/Platforms/Windows/Impl/PopupPlatformWindows.cs | 1 + RGPopup.Maui/Platforms/iOS/Impl/PopupPlatformIos.cs | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/RGPopup.Maui/Platforms/Android/Impl/PopupPlatformDroid.cs b/RGPopup.Maui/Platforms/Android/Impl/PopupPlatformDroid.cs index 96a65e9..33c1bc5 100644 --- a/RGPopup.Maui/Platforms/Android/Impl/PopupPlatformDroid.cs +++ b/RGPopup.Maui/Platforms/Android/Impl/PopupPlatformDroid.cs @@ -35,7 +35,7 @@ public event EventHandler OnInitialized public Task AddAsync(PopupPage page) { HandleAccessibilityWorkaround(page, ImportantForAccessibility.NoHideDescendants); - + page.Parent = XApplication.Current?.MainPage; var pageHandler = page.GetOrCreateHandler(); DecorView?.AddView(pageHandler.PlatformView); @@ -56,7 +56,8 @@ public Task RemoveAsync(PopupPage page) page.Parent = null; //If manual dispose the view's renderer, but the view is not disposed at the same time, it will crash when repush the view. //renderer.Dispose(); - + page.Handler?.DisconnectHandler(); + if (DecorView != null) return PostAsync(DecorView); } diff --git a/RGPopup.Maui/Platforms/MacCatalyst/Impl/PopupPlatformMacOS.cs b/RGPopup.Maui/Platforms/MacCatalyst/Impl/PopupPlatformMacOS.cs index 19df6af..550079b 100644 --- a/RGPopup.Maui/Platforms/MacCatalyst/Impl/PopupPlatformMacOS.cs +++ b/RGPopup.Maui/Platforms/MacCatalyst/Impl/PopupPlatformMacOS.cs @@ -89,6 +89,7 @@ public async Task RemoveAsync(PopupPage page) { var window = viewController.View?.Window; page.Parent = null; + page.Handler?.DisconnectHandler(); if (window != null) { var rvc = window.RootViewController; diff --git a/RGPopup.Maui/Platforms/Windows/Impl/PopupPlatformWindows.cs b/RGPopup.Maui/Platforms/Windows/Impl/PopupPlatformWindows.cs index 136c3b4..97c7558 100644 --- a/RGPopup.Maui/Platforms/Windows/Impl/PopupPlatformWindows.cs +++ b/RGPopup.Maui/Platforms/Windows/Impl/PopupPlatformWindows.cs @@ -65,6 +65,7 @@ public async Task RemoveAsync(PopupPage page) { popup.IsOpen = false; page.Parent = null; + page.Handler?.DisconnectHandler(); } await Task.Delay(5); diff --git a/RGPopup.Maui/Platforms/iOS/Impl/PopupPlatformIos.cs b/RGPopup.Maui/Platforms/iOS/Impl/PopupPlatformIos.cs index d0062ca..92dea35 100644 --- a/RGPopup.Maui/Platforms/iOS/Impl/PopupPlatformIos.cs +++ b/RGPopup.Maui/Platforms/iOS/Impl/PopupPlatformIos.cs @@ -86,6 +86,7 @@ public async Task RemoveAsync(PopupPage page) { var window = viewController.View?.Window; page.Parent = null; + page.Handler?.DisconnectHandler(); if (window != null) { var rvc = window.RootViewController;