[BR] Issues with native alert windows

Hi there!

Thanks for the recent changes to MessageBoxOptions which added an explicit resultCode, that’s a very welcome change!

But I have found some problems with native dialogs, specially the simple yes/cancel dialogues and the order in which the buttons are displayed. (These dialogues are very common, so I think it would be a good idea to add one to the DemoRunner, by the way).

On Windows the custom is to place [YES] on the left and [CANCEL] on the right. On macOS, iOS and Android it is the other way around, with [CANCEL] on the left and [YES] on the right.

On both macOS and Android (but not on iOS) JUCE currently reverses the order of the buttons on native dialogues relative to the order used in the MessageBoxOptions. So if I create a dialogue adding first the yes button and then the cancel button, it will display the native dialogue “correctly” on all platforms, except on iOS.

Also, the documentation states that “On Android, native message boxes may be dismissed by tapping outside the box. In this case, the result code will match that of the final button in the MessageBoxOptions. If there are no buttons, the result code will be 0.”

Nevertheless, I have found that the result code is always 0 when closing by tapping outside of the box (which I think makes more sense anyway) and does NOT match any button.

Also, on iOS the leftmost button on a two-option dialogue is marked bold. It should be the rightmost button.

It would be brilliant if these minor issues could be fixed so that native dialogues behave more consistently.

1 Like

I think it would be best for the API to explicitly determine the default button (selected with enter) and the cancel button (selected with cancel or tapping elsewhere in the case of Android), for example:

.withDefaultButton ("OK", 1)
.withCancelButton ("Cancel", 0)
.withButton ("Tell me more", 2)

That way when using non-native dialogues it would be possible to determine the order as one pleases but when using native dialogues these would be placed on their “correct” spot with no guesswork involved.

Thanks for the feedback. We’ve added the ability to specify primary/cancel/destructive buttons here:

1 Like

That is excellent! Tested on Android, iOS and macOS and as far as I can see everything works perfectly.

I also tested using some older Android themes, such as @android:style/Theme or @android:style/Theme.Holo. I noticed that the buttons are then displayed in a different order, but I believe that they are following the conventions used back then so that’s not a bug.

Thank you very much!

1 Like

One question: “On Android, two- and three-button native message boxes created using
MessageBoxOptions::withButton() no longer have cancellation behaviour (where
the box can be dismissed by tapping outside) by default.” Why doesn’t this apply to single-button message boxes as well? Currently it is not possible to create a single-button message box which cannot be dismissed by tapping outside or using the back gesture. It would be nice to have the option.

This sounds familiar!

Ah yes, these problems have existed for a while now! But as far as I can tell the problems described on that thread were solved now by adding explicit button result codes and roles to the MessageBoxOptions.

Why do Android one-button message boxes have cancellation behaviour by default, unlike two- or three-button boxes?

Thanks, that’s a good point. We’ve updated the single-button behaviour so that the dialog can only be dismissed if the button has the ‘cancel’ role.

Ah that’s brilliant, thanks a ton!