Skip to content

Commit

Permalink
Call RootViewChanged when setting ContentView to null (#20052)
Browse files Browse the repository at this point in the history
* Call RootViewChanged when setting ContentView to null

* When switching RootView, Reinitialize VisualDiagnosticsLayer

---------

Co-authored-by: Shane Neuville <shneuvil@microsoft.com>
  • Loading branch information
drasticactions and PureWeen authored Jun 1, 2024
1 parent 7b2fafb commit fcabff1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/Core/src/Handlers/Window/WindowHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -155,6 +155,8 @@ void SetContentView(IView? view)

if (FragmentManager.IsDestroyed(context))
_viewFragment = null;

RootViewChanged?.Invoke(this, EventArgs.Empty);
}
else
{
Expand Down

0 comments on commit fcabff1

Please sign in to comment.