From fcabff1fe3e551e22558cba74dd3a86e00323b69 Mon Sep 17 00:00:00 2001 From: Tim Miller Date: Sun, 2 Jun 2024 04:18:47 +0900 Subject: [PATCH] Call RootViewChanged when setting ContentView to null (#20052) * Call RootViewChanged when setting ContentView to null * When switching RootView, Reinitialize VisualDiagnosticsLayer --------- Co-authored-by: Shane Neuville --- .../Compatibility/Handlers/Shell/Android/ShellRenderer.cs | 3 --- src/Core/src/Handlers/Window/WindowHandler.Android.cs | 5 +++++ .../src/Platform/Android/Navigation/NavigationRootManager.cs | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellRenderer.cs index ba82a9af33a1..46ca471ab82d 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellRenderer.cs @@ -214,9 +214,6 @@ protected virtual void OnElementSet(Shell shell) ((IShellController)shell).AddAppearanceObserver(this, shell); SwitchFragment(FragmentManager, _frameLayout, shell.CurrentItem, false); - - var rootManager = _mauiContext.GetNavigationRootManager(); - rootManager?.OnWindowContentPlatformViewCreated(); } IShellItemRenderer _currentView; diff --git a/src/Core/src/Handlers/Window/WindowHandler.Android.cs b/src/Core/src/Handlers/Window/WindowHandler.Android.cs index 3da60b24d7bd..bdb4260cbb81 100644 --- a/src/Core/src/Handlers/Window/WindowHandler.Android.cs +++ b/src/Core/src/Handlers/Window/WindowHandler.Android.cs @@ -73,7 +73,12 @@ private protected override void OnDisconnectHandler(object platformView) void OnRootViewChanged(object? sender, EventArgs e) { if (VirtualView.VisualDiagnosticsOverlay != null && _rootManager?.RootView is ViewGroup) + { + if (VirtualView.VisualDiagnosticsOverlay.IsPlatformViewInitialized) + VirtualView.VisualDiagnosticsOverlay.Deinitialize(); + VirtualView.VisualDiagnosticsOverlay.Initialize(); + } } // This is here to try and ensure symmetry with disconnect code between test handler diff --git a/src/Core/src/Platform/Android/Navigation/NavigationRootManager.cs b/src/Core/src/Platform/Android/Navigation/NavigationRootManager.cs index 8d14bed8cca4..841d7dd3a763 100644 --- a/src/Core/src/Platform/Android/Navigation/NavigationRootManager.cs +++ b/src/Core/src/Platform/Android/Navigation/NavigationRootManager.cs @@ -95,7 +95,7 @@ internal void Connect(IView view, IMauiContext? mauiContext = null) // this is called after the Window.Content is created by // the fragment. We can't just create views on demand // need to let the fragments fall - internal void OnWindowContentPlatformViewCreated() + void OnWindowContentPlatformViewCreated() { RootViewChanged?.Invoke(this, EventArgs.Empty); @@ -155,6 +155,8 @@ void SetContentView(IView? view) if (FragmentManager.IsDestroyed(context)) _viewFragment = null; + + RootViewChanged?.Invoke(this, EventArgs.Empty); } else {