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

Popup displayed behind modal #143

Open
NovaKs68 opened this issue Nov 15, 2024 · 7 comments · May be fixed by #152
Open

Popup displayed behind modal #143

NovaKs68 opened this issue Nov 15, 2024 · 7 comments · May be fixed by #152

Comments

@NovaKs68
Copy link

Issue : Mopups displayed behind Shell Modals
How to reproduce :

Steps that work :

  1. Open a Shell Page.
  2. In this page, open a Mopup dialog.
  3. The Mopup is visible in front of the Page.

Steps with problems :

  1. Open a Shell Modal.
  2. In this modal, open a dialog Mopup.
  3. It opens behind the modal. Go back and you'll see the Mopup.

.Net version : 9.0
Tested platform : Android emulator
Repo for reproduction : https://github.com/NovaKs68/TestMaui

@jyamona
Copy link

jyamona commented Nov 15, 2024

Same issue here. It also is affecting non-shell apps as well.

Steps to reproduce:

  1. On a navigation page, push a modal using PushModalAsync();
  2. On that modal page, try to display a Mopup.
  3. It opens behind the modal, if you close the modal you will see the Mopup.

.NET 9.0
Testing on a few physical Android devices. iOS works as intended.

@afk013
Copy link

afk013 commented Nov 25, 2024

Duplicate of #82

@BillFulton
Copy link

It's an extremely serious limitation. Hoping for a release that will fix this.

@arosanti
Copy link

Anyone have a workaround for this at all?

@vecalion
Copy link

Anyone have a workaround for this at all?

We migrated to MCT Popups (https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/views/popup), and it was surprisingly easy to do. Not sure if that qualifies as a workaround, though :)

@DashTheDev
Copy link

DashTheDev commented Jan 23, 2025

Check out my pretty bleh workaround @arosanti.

Since the way MAUI presents Modals changed in .NET 9, popups don't appear in front as Modals are their own fragments now. This is also alluded to in #82.

To address this, I sticky taped the code in the AndroidMopups.cs to account for that so that popups appear in front of the top fragment, whether that's a dialog fragment or the main activity window. It's been working for me for the past 3-4 months, no problems so far. Obviously the code can be improved and it doesn't account for every window & fragment setup, etc, etc. But it works for now.

See below for the workaround version of AndroidMopups.cs (at least the changes), specifically the DecoreView property and the GetTopFragmentDecorView() method.

public class AndroidMopups : IPopupPlatform
{
    private static FrameLayout? DecoreView => GetTopFragmentDecorView();

    ...

    public Task AddAsync(PopupPage page)
    {
        ...
        var androidNativeView = handler.PlatformView as Android.Views.View;
        DecoreView?.AddView(androidNativeView);
        ...
    }

    // TODO: This fixes https://github.com/LuckyDucko/Mopups/issues/82. But we should monitor and implement their fix when it's done
    private static FrameLayout? GetTopFragmentDecorView()
    {
        if (Platform.CurrentActivity is not ComponentActivity componentActivity)
        {
            return null;
        }

        IList<AndroidX.Fragment.App.Fragment>? fragments = componentActivity.GetFragmentManager()?.Fragments;

        if (fragments is null || !fragments.Any())
        {
            return null;
        }

        AndroidX.Fragment.App.Fragment topFragment = fragments[^1];

        if (topFragment is AndroidX.Fragment.App.DialogFragment dialogFragment)
        {
            return dialogFragment.Dialog?.Window?.DecorView as FrameLayout;
        }

        return topFragment.Activity?.Window?.DecorView as FrameLayout;
    }
    
   ...
}

@happyfr34k
Copy link

Can we expect an official fix in the short to medium term?
Mopups are now unusable in our project... :-(

@AnthonyNjuguna AnthonyNjuguna linked a pull request Feb 4, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants