Merge pull request #157 from spadapet/dev/spadapet/FixXamlHotReloadInPopup

Add support for XAML Hot Reload in Visual Studio (and VS Code)
This commit is contained in:
Tyson Elliot Hooker
2025-05-16 13:54:28 +10:00
committed by GitHub
4 changed files with 14 additions and 15 deletions

View File

@@ -43,8 +43,8 @@ public class AndroidMopups : IPopupPlatform
{
HandleAccessibility(true, page.DisableAndroidAccessibilityHandling, page);
page.Parent = MauiApplication.Current.Application.Windows[0].Content as Element;
page.Parent ??= MauiApplication.Current.Application.Windows[0].Content as Element;
var mainPage = (Element)MauiApplication.Current.Application.Windows[0].Content;
mainPage.AddLogicalChild(page);
var handler = page.Handler ??= new PopupPageHandler(page.Parent.FindMauiContext());
@@ -67,7 +67,7 @@ public class AndroidMopups : IPopupPlatform
decoreView?.RemoveView(renderer.PlatformView as Android.Views.View);
}
renderer.DisconnectHandler(); //?? no clue if works
page.Parent = null;
page.Parent?.RemoveLogicalChild(page);
return PostAsync(DecoreView);
}

View File

@@ -22,7 +22,8 @@ internal class MacOSMopups : IPopupPlatform
public Task AddAsync(PopupPage page)
{
page.Parent = Application.Current.MainPage;
var mainPage = Application.Current.MainPage;
mainPage.AddLogicalChild(page);
page.DescendantRemoved += HandleChildRemoved;
@@ -102,7 +103,7 @@ internal class MacOSMopups : IPopupPlatform
if (handler != null && viewController != null && !viewController.IsBeingDismissed)
{
var window = viewController.View?.Window;
page.Parent = null;
page.Parent?.RemoveLogicalChild(page);
if (window != null)
{

View File

@@ -51,7 +51,8 @@ namespace Mopups.Windows.Implementation
public async Task AddAsync(PopupPage page)
{
page.Parent = Application.Current.MainPage;
var mainPage = Application.Current.MainPage;
mainPage.AddLogicalChild(page);
var popup = new global::Microsoft.UI.Xaml.Controls.Primitives.Popup();
@@ -62,16 +63,12 @@ namespace Mopups.Windows.Implementation
// Then you can use contructor resolution instead of singletons
// But I figured we could do that in a later PR and just work on windows here
var renderer = (PopupPageRenderer)page.ToPlatform(Application.Current.MainPage.Handler.MauiContext);
var renderer = (PopupPageRenderer)page.ToPlatform(mainPage.Handler.MauiContext);
renderer.Prepare(popup);
popup.Child = renderer;
// https://github.com/microsoft/microsoft-ui-xaml/issues/3389
popup.XamlRoot =
Application.Current.MainPage.Handler.MauiContext.Services.GetService<Microsoft.UI.Xaml.Window>().Content.XamlRoot;
popup.XamlRoot = mainPage.Handler.MauiContext.Services.GetService<Microsoft.UI.Xaml.Window>().Content.XamlRoot;
popup.IsOpen = true;
page.ForceLayout();
@@ -91,7 +88,7 @@ namespace Mopups.Windows.Implementation
renderer.Destroy();
Cleanup(page);
page.Parent = null;
page.Parent?.RemoveLogicalChild(page);
popup.Child = null;
popup.IsOpen = false;
}

View File

@@ -16,7 +16,8 @@ internal class iOSMopups : IPopupPlatform
public Task AddAsync(PopupPage page)
{
page.Parent ??= Application.Current?.MainPage;
var mainPage = Application.Current.MainPage;
mainPage.AddLogicalChild(page);
var keyWindow = GetKeyWindow(UIApplication.SharedApplication);
if (keyWindow?.WindowLevel == UIWindowLevel.Normal)
@@ -87,7 +88,7 @@ internal class iOSMopups : IPopupPlatform
if (handler != null && viewController != null && !viewController.IsBeingDismissed)
{
var window = viewController.View?.Window;
page.Parent = null;
page.Parent?.RemoveLogicalChild(page);
if (window != null)
{