Page.DisplayAlert and Page.DisplayActionSheet do not work in MAUI Embedded Use Case #19843
Labels
area-controls-dialogalert
DisplayAlert, dialog
migration-compatibility
Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert
platform/android 🤖
platform/iOS 🍎
s/triaged
Issue has been reviewed
s/verified
Verified / Reproducible Issue ready for Engineering Triage
t/bug
Something isn't working
t/native-embedding
Milestone
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
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
The text was updated successfully, but these errors were encountered: