Skip to content

Page.DisplayAlert and Page.DisplayActionSheet do not work in MAUI Embedded Use Case #19843

@nau-dwb

Description

@nau-dwb

Description

When using MAUI under the embedded use case within a native .NET Android or .NET iOS application, the Page.DisplayAlert and Page.DisplayActionSheet methods do not work in either iOS or Android. I have not tried Page.DisplayPromptAsync but suspect that would not work either.

This worked fine in the Xamarin realm when using Xamarin Forms embedded in Xamarin Android or Xamarin iOS.

This also works fine if using "pure" MAUI and not the embedded use case.

Looking in the MAUI source code, it looks like the underlying implementation of these methods use the MessagingCenter to send a message. I suspect when using MAUI embedded, the applicable subscriptions to these messages are not being registered like they are in "pure" MAUI.

Steps to Reproduce

  1. Create a new .NET 7 Android or iOS project using embedded MAUI. Does not matter if it's a single project structure or separate projects for the Android\iOS and MAUI code.
  2. Create a MAUI page with a button or label with a tap gesture recognizer - anything you can tap and fire a command with.
  3. Implement the command to await DisplayAlert or DisplayActionSheet
  4. Do something with the variable holding the result from the prior call (even just a console writeline with it) and place a break point here.
  5. Run the app, tap the button\label\etc.

Note: You can run the simple-maui-embedded sample application under the provided repo to reproduce this issue.

Expected: the alert or action sheet display to the user and the user can make a selection - breakpoint dealing with the result from the dialog is hit.

Actual: No dialog or action sheet is displayed. Breakpoint after is never hit. No exception is thrown but the alert never appears.

Link to public reproduction project repository

https://github.com/nau-dwb/maui-embedded-use-issues/tree/main

Version with bug

Unknown/Other

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, I was not able test on other platforms

Affected platform versions

Android 26+ and iOS 14.2+ with .NET 7

Did you find any workaround?

Working around this currently by using the native Android and iOS options for alert dialogs\prompts\action sheets. We have an interface defining methods to invoke a dialog\prompt\action sheet that the MAUI code interacts with and then an Android and iOS implementation using the native code that we register with the DI container on start up.

Note the provided repo is solely for simple repro purposes and does NOT contain an example of this workaround.

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions