Button order on native.showAlert("title", "message", {"OK","Cancel"})

Hi all,

Seeing a strange ordering on buttons using native.showAlert(…)

See attached image. Any thoughts?

Thanks all

The macOS naturally shows dialog box buttons in reverse order. This is normal behavior.

Rob

Thanks for confirming Rob.

I’m picking this up, because I noticed an issue with the button order on Android 8:

native.showAlert ("Title", "Message", { "Button1", "Button2", "Button3" }, onComplete)

This will result in the following quite random order on Android 8 (can’t test other versions at the moment):

Button2
Button3
Button1

I am using Build 3308.

Best regards!

Glad it’s not just me. Seeing similar, thought I was going mad. Can we get a fix for this? Or a timeline?

Chinning in unasked, but I don’t think Corona will change this.  It would change an existing feature upon which others may depend, and it is relatively low priority compared to big ticket items and ANRs, continuing GDPR changes, etc.

You can fix this yourself  by over-ridding the native.showAlert call.  I’ll post a solution for you in a few minutes.

Ok thanks.

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/06/override_showAlert.zip

  1. Decide the behavior you want.

  2. Test on all targets and see what the default is.

  3. Modify the code I provided to override behavior for those platforms that do not behave as you want them to.

Currently only modifying for Mac OSX, but I think Windows also reverses the label list, so you probably want to reverse it automatically too.

  1. Re-test.

  2. Done forever.

Thank you very much for your efforts! However, the problem is not that the order is just reversed - the button order is completely messed up on Android. So a potential “Close” button would appear anywhere in the middle.

Yes it’s seemingly random. Almost like it decides at run time, weird.

If you do Button1, Button2, and Button3 on Android 8 will Button3 always be the middle button or are you saying “random order” in that it may on one run be first another last, and a third run in the middle?

Rob

I’ll do some tests for you, but from memory it’s different most times, impossible to give the user safe guidance on where a button will be.

Hi. What exact version of Android are you running and what device are you running on?

Ah, I missed it.  Android 8?  Is that correct?

FWIW, On android 4.4.2, the button order matches the labels order passed in.

Here is and updated copy of the fix and an APK built with: 2018.3297

Buttons should come out in the order of the numbers in the labels (not the alpha parts):

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/06/override_showAlert.zip

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/06/override_showAlert_APK_2018.3297.zip

For me the order is always the same at runtime, but different depending on the number of buttons:

“1”, “2” => “2”, “1” (horizontal)

“1”, “2”, “3” => “2”, “3”, “1” (horizontal)

“1”, “2”, “3”, “4” => “1”, “2”, “3”, “4” (vertical)
“1”, “2”, “3”, “4”, “5” => “1”, “2”, “3”, “4”, “5” (vertical)

So it’s seems like the problem is only with less than 4 buttons, when they are displayed horizontal. It seems like the first element is put at the end in this case. However, I can’t test how this behaves with other Android versions at the moment.

Best regards!

Not sure it’s based on the number of option, it’s one of space. On my OnePlus the buttons are always horizontal, on my Moto G5 they are always vertical but always in a different order.

The location is defined by the operating system and screen real estate, android tablets will likely always be horizontal (surely?)

Not had chance to do my tests but will asap. As you have that code working @bjoern perhaps change 1,2,3 for real world example of wording like: New Game, Save, Reply, Upload and Screenshot

We just ran some tests on iOS and Android using 2 buttons in landscape, and it appears that the orders are reverse for the 2 as well. argh…

Apple products put the Okay button on the right of the list.  Windows and Android would likely want to display:

Okay   Cancel

But macOS, iOS etc want to display

Cancel  Okay

If we just output them in the order you provided you would have to write if statements for every native.showDialog() to reorder the buttons in the way the native OS wants them. This is expected behavior.

Rob

Rob - that’s the thing that’s weird for us. We found that the Mac Simulator and the iOS devices use different orders. Attached is our test code and resulting screenshots. We are using Corona 2018.3389.

https://www.dropbox.com/s/mimg88qdlwtbejt/showAlertTest.zip?dl=0

We are OK if this is the expected behavior (vs a bug), but want to be sure before we put in our own code. Thanks.

The macOS naturally shows dialog box buttons in reverse order. This is normal behavior.

Rob

Thanks for confirming Rob.