Fix support for VisualDiagnosticsOverlay/IWindowOverlay on Android Shell Apps #16138
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With MAUI Shell Apps on Android, WindowOverlay and VisualDiagnosticOverlay don't work. If you try to hover over the live visual tree in Visual Studio, the elements that should be highlighted are not. If you try and add your own WindowOverlay to an existing window (Which you can do but is not documented anywhere, but trust me when I say that it is!) it does not appear.
This, I believe, is do to the way Shell and Non-Shell apps handle the initial Window startup.
maui/src/Core/src/Platform/Android/Navigation/NavigationRootManager.cs
Lines 123 to 152 in 43b9397
When setting the initial NavigationRootManager for Android, the delegate
OnWindowContentPlatformViewCreated
gets called when the initial Fragment for the application gets made. This gets called back into the Window Handler code, which invokes the VisualDiagnosticOverlay handler initialization, allowing Window Overlay code to work. For Shell apps though, this code doesn't get fired, the view in SetContent is null.This is called out in the comment above,
maui/src/Core/src/Platform/Android/Navigation/NavigationRootManager.cs
Lines 79 to 84 in 43b9397
Shell apps handle their fragments through other means. Still, because of this, the RootViewChanged logic in the Window Handler never gets called, meaning the VisualDiagnosticsOverlay code never gets run, meaning overlays won't work. The overlay logic has to be run after the initial views are laid out to be placed on top of the existing views., so there needs to be similar logic in place for shell apps.
I tried putting it inside of the ShellRenderer, after its logic is run and the fragments are switched, that means the views should have been loaded and should be safe for us to call the VisualDiagnosticOverlay logic on the Window to get it to run.
I'm not sure if this is the right thing to do here, but hopefully, this shows the issue at hand for why it's happening.
Fixes #10781