maui icon indicating copy to clipboard operation
maui copied to clipboard

DisplayActionSheet doesn't show up on macOS

Open Auto72 opened this issue 1 year ago • 12 comments

Description

DisplayActionSheet doesn't show up on macOS.

Steps to Reproduce

private async void OnActionSheetClicked(object sender, EventArgs e)
{
    string action = await DisplayActionSheet("", "Cancel", null, "Option #1", "Option #2", "Option #3", "Option #4");
    await DisplayAlert("DisplayActionSheet Result", $"Action: {action}", "OK");
}

Link to public reproduction project repository

No response

Version with bug

8.0.0-rc.2.9373

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

macOS

Affected platform versions

net8.0-maccatalyst | macOS 14.0

Did you find any workaround?

No.

Relevant log output

.

Auto72 avatar Oct 19 '23 15:10 Auto72

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

ghost avatar Oct 19 '23 18:10 ghost

I believe this also affects net7.0-maccatalyst, as I'm seeing the same issue when building under dotnet 7.0.309.

Matthewrbowker avatar Oct 21 '23 08:10 Matthewrbowker

If you simply add the DisplayActionSheet to the OnCounterClicked handler of the standard Maui app the action sheet does not appear and following statements are not executed. On Windows and Android this works as expected. I also suddenly have in my app when running on MacCatalyst MenuBarItems in my XAML that do not respond when clicked. I have a feeling these problems are related.

private void OnCounterClicked(object sender, EventArgs e)
{
	count++;

	this.DisplayActionSheet("What type of condition?", "Cancel", null, "Source Condition", "Position Condition", "Attribute Condition", "Affected By Condition");

    if (count == 1)
		CounterBtn.Text = $"Clicked {count} time";
	else
		CounterBtn.Text = $"Clicked {count} times";

	SemanticScreenReader.Announce(CounterBtn.Text);
}

cdavidyoung avatar Oct 26 '23 22:10 cdavidyoung

I ran into the same issue, and was getting the following null reference exception, .NET 7.0.401

await Application.Current.MainPage.DisplayActionSheet("Title", "Cancel", null, "test", "test1", "test2");
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Maui.Controls.Platform.AlertManager.AlertRequestHelper.PresentPopUp(Window virtualView, UIWindow platformView, UIAlertController alert, ActionSheetArguments arguments)
   at Microsoft.Maui.Controls.Platform.AlertManager.AlertRequestHelper.PresentActionSheet(ActionSheetArguments arguments)
   at Microsoft.Maui.Controls.Platform.AlertManager.AlertRequestHelper.OnActionSheetRequested(Page sender, ActionSheetArguments arguments)
   at System.Reflection.MethodInvoker.InterpretedInvoke(Object obj, Span`1 args, BindingFlags invokeAttr)
   --- End of inner exception stack trace ---
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Microsoft.Maui.Controls.MessagingCenter.Subscription.InvokeCallback(Object sender, Object args)
   at Microsoft.Maui.Controls.MessagingCenter.InnerSend(String message, Type senderType, Type argType, Object sender, Object args)
   at Microsoft.Maui.Controls.MessagingCenter.Microsoft.Maui.Controls.IMessagingCenter.Send[Page,ActionSheetArguments](Page sender, String message, ActionSheetArguments args)
   at Microsoft.Maui.Controls.MessagingCenter.Send[Page,ActionSheetArguments](Page sender, String message, ActionSheetArguments args)
   at Microsoft.Maui.Controls.Page.DisplayActionSheet(String title, String cancel, String destruction, FlowDirection flowDirection, String[] buttons)
   at Microsoft.Maui.Controls.Page.DisplayActionSheet(String title, String cancel, String destruction, String[] buttons)
   at RevisionPlanner.ViewModel.DashboardPageViewModel.OnAddExamButtonPressed() in /RevisionPlanner/ViewModel/DashboardPageViewModel.cs:line 30

rednir avatar Oct 27 '23 11:10 rednir

When I run the standard Maui app described above, with or without the change, it outputs this message when it starts up. It seems DisplayActionSheet is getting called from somewhere and already reporting a problem.

Thread started: <Thread Pool> #10 2023-10-27 09:08:03.915 DisplayActionSheet test[6451:66528] Warning: observer object was not disposed manually with Dispose() 2023-10-27 09:08:03.915 DisplayActionSheet test[6451:66528] Warning: observer object was not disposed manually with Dispose() Thread finished: <Thread Pool> #10

cdavidyoung avatar Oct 27 '23 16:10 cdavidyoung

When I run the standard Maui app described above, with or without the change, it outputs this message when it starts up. It seems DisplayActionSheet is getting called from somewhere and already reporting a problem.

Thread started: #10 2023-10-27 09:08:03.915 DisplayActionSheet test[6451:66528] Warning: observer object was not disposed manually with Dispose() 2023-10-27 09:08:03.915 DisplayActionSheet test[6451:66528] Warning: observer object was not disposed manually with Dispose() Thread finished: #10

I was seeing this message before I had issues with DisplayActionSheet, though.

Matthewrbowker avatar Oct 28 '23 21:10 Matthewrbowker

Yes, but perhaps it was trying to tell us something. I would think that warning should be fixed in any case and perhaps it will resolve this problem.

On Sat, Oct 28, 2023 at 2:33 PM Matthew Bowker @.***> wrote:

When I run the standard Maui app described above, with or without the change, it outputs this message when it starts up. It seems DisplayActionSheet is getting called from somewhere and already reporting a problem.

Thread started: #10 https://github.com/dotnet/maui/issues/10 2023-10-27 09:08:03.915 DisplayActionSheet test[6451:66528] Warning: observer object was not disposed manually with Dispose() 2023-10-27 09:08:03.915 DisplayActionSheet test[6451:66528] Warning: observer object was not disposed manually with Dispose() Thread finished: #10 https://github.com/dotnet/maui/issues/10

I was seeing this message before I had issues with DisplayActionSheet, though.

— Reply to this email directly, view it on GitHub https://github.com/dotnet/maui/issues/18156#issuecomment-1783925433, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHE7KZZLKVLRUTTB36H7CLYBV235AVCNFSM6AAAAAA6HM4FGSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBTHEZDKNBTGM . You are receiving this because you commented.Message ID: @.***>

cdavidyoung avatar Oct 28 '23 23:10 cdavidyoung

@Matthewrbowker One more datapoint is that DisplayAlert seems to work fine. I suppose I could convert the DisplayActionSheet in my app to a series of DisplayAlert but that would be rather awkward. : ) Besides that, the other thing that is not working for me are MenuBarItems. I have a feeling that when DisplayActionSheet is fixed it will fix MenuBarItems as well.

cdavidyoung avatar Nov 02 '23 15:11 cdavidyoung

@Matthewrbowker Here is another clue. My main development Mac is an M1 with the latest updates. I have an old Mac Mini 2014 available as well so I decided to try my app on it. Wouldn't you know it. The DisplayActionSheet and MenuBarItems work fine on it. Here are screenshots. Is there anything else I can do to help diagnose this?

Image 11-4-23 at 7 09 AM Image 11-4-23 at 7 10 AM Image 11-4-23 at 7 12 AM

cdavidyoung avatar Nov 04 '23 14:11 cdavidyoung

I can confirm this issue. A delivered program has suddenly stopped working. On a computer with Sonoma 14.1 installed, DisplayActionSheet no longer runs and no action sheet is displayed. On an older computer with Ventura 13.6.1, no error occurs and the action sheet is displayed.

ultra133 avatar Nov 04 '23 15:11 ultra133

Same issue here, with Sonoma 14.1 installed. Is there any workaround or are we forced to wait for an hotfix?

mwnovaprove avatar Nov 13 '23 16:11 mwnovaprove

Since calling an action sheet with UIKit is really a no-brainer, this could be an easy workaround for those who can't wait for a fix:

#if MACCATALYST
        if ((Handler as PageHandler)?.ViewController is not UIViewController viewController) return;

        var completion = new TaskCompletionSource<string>();

        var alert = UIAlertController.Create("Caption", null, UIAlertControllerStyle.ActionSheet);
        alert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, _ => completion.TrySetResult("Cancel")));
        alert.AddAction(UIAlertAction.Create("One", UIAlertActionStyle.Default, _ => completion.TrySetResult("One")));
        alert.AddAction(UIAlertAction.Create("Two", UIAlertActionStyle.Default, _ => completion.TrySetResult("Two")));
        alert.AddAction(UIAlertAction.Create("Three", UIAlertActionStyle.Default, _ => completion.TrySetResult("Three")));
        viewController.PresentViewController(alert, true, null);

        var result = await completion.Task;
#else
        var result = await DisplayActionSheet("Caption", "Cancel", null, "One", "Two", "Three");
#endif

ultra133 avatar Jan 04 '24 09:01 ultra133

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Maui.Controls.Platform.AlertManager.AlertRequestHelper.PresentPopUp(Page sender, Window virtualView, UIWindow platformView, UIAlertController alert, ActionSheetArguments arguments)
   at Microsoft.Maui.Controls.Platform.AlertManager.AlertRequestHelper.PresentActionSheet(Page sender, ActionSheetArguments arguments)
   at Microsoft.Maui.Controls.Platform.AlertManager.AlertRequestHelper.OnActionSheetRequested(Page sender, ActionSheetArguments arguments)
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
   --- End of inner exception stack trace ---
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Microsoft.Maui.Controls.MessagingCenter.Subscription.InvokeCallback(Object sender, Object args)
   at Microsoft.Maui.Controls.MessagingCenter.InnerSend(String message, Type senderType, Type argType, Object sender, Object args)
   at Microsoft.Maui.Controls.MessagingCenter.Microsoft.Maui.Controls.IMessagingCenter.Send[Page,ActionSheetArguments](Page sender, String message, ActionSheetArguments args)
   at Microsoft.Maui.Controls.MessagingCenter.Send[Page,ActionSheetArguments](Page sender, String message, ActionSheetArguments args)
   at Microsoft.Maui.Controls.Page.DisplayActionSheet(String title, String cancel, String destruction, FlowDirection flowDirection, String[] buttons)

Mac Studio, M2 Ultra, 64GB, Sonoma 14.2.1, Xcode 15.2, VS for Mac 17.6.8.400, .NET 8.0.100

PLEASE FIX THIS

KMWenyon avatar Jan 19 '24 00:01 KMWenyon

This will impact any iOS apps published on the store that are set to be allowed to run on M-procesor Macs. So even if you haven't specifically released a Mac version of your app, your users may still be launching the iOS app on Mac and getting the crash.

It looks like there is a fix in progress in the PR #19629 which is good!

BurkusCat avatar Mar 27 '24 22:03 BurkusCat