Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix support for VisualDiagnosticsOverlay/IWindowOverlay on Android Shell Apps #16138

Merged
merged 1 commit into from
Aug 22, 2023

Conversation

drasticactions
Copy link
Contributor

image

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.

void SetContentView(IView? view)
{
if (view == null)
{
if (_viewFragment != null && !FragmentManager.IsDestroyed(_mauiContext.Context))
{
FragmentManager
.BeginTransaction()
.Remove(_viewFragment)
.SetReorderingAllowed(true)
.Commit();
}
_viewFragment = null;
}
else
{
_viewFragment =
new ElementBasedFragment(
view,
_mauiContext!,
OnWindowContentPlatformViewCreated);
FragmentManager
.BeginTransaction()
.Replace(Resource.Id.navigationlayout_content, _viewFragment)
.SetReorderingAllowed(true)
.Commit();
}
}

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,

// if the incoming view is a Drawer Layout then the Drawer Layout
// will be the root view and internally handle all if its view management
// this is mainly used for FlyoutView
//
// if it's not a drawer layout then we just use our default CoordinatorLayout inside navigationlayout
// and place the content there

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

@jsuarezruiz jsuarezruiz added t/housekeeping ♻︎ area-controls-shell Shell Navigation, Routes, Tabs, Flyout labels Jul 13, 2023
@rachelkang
Copy link
Member

interesting, thanks for explaining!

(not reviewing, just here to learn)

@samhouts samhouts added area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging platform/android 🤖 and removed t/housekeeping ♻︎ labels Jul 19, 2023
@samhouts samhouts added this to the Under Consideration milestone Aug 15, 2023
@drasticactions drasticactions merged commit 74b3c38 into dotnet:main Aug 22, 2023
@drasticactions drasticactions deleted the dev/timill/shell-android branch August 22, 2023 08:42
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2023
@samhouts samhouts removed this from the Under Consideration milestone Jul 1, 2024
@samhouts samhouts added the fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171 label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171 platform/android 🤖
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Android] WindowOvelay painting is not working with shell
4 participants