Titanium JIRA Archive
Appcelerator Community (AC)

[AC-4758] Android: add autoClose to AlertDialog to keep it open after clicking

GitHub Issuen/a
TypeNew Feature
Priorityn/a
StatusResolved
ResolutionWon't Fix
Resolution Date2017-01-29T16:16:33.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
LabelsalertDialog, android, community
ReporterMichael Gangolf
AssigneeShak Hossain
Created2017-01-28T13:35:48.000+0000
Updated2017-01-29T16:16:33.000+0000

Description

Adding an autoClose property that will keep the AlertDialog open after clicking a button. Default will be true so it will the same behaviour as before. You have to manually call hide() to close the dialog when autoClose:false *Test code*
Ti.UI.setBackgroundColor('white');
var win = Ti.UI.createWindow({
    title: 'Click window to test',
    backgroundColor: 'white',
    layout: "vertical"
});

var btn1 = Ti.UI.createButton({
    title: "Alert 1"
});
win.add(btn1);
var btn2 = Ti.UI.createButton({
    title: "Alert 2"
});
win.add(btn2);
var btn3 = Ti.UI.createButton({
    title: "Alert 3"
});
win.add(btn3);

btn1.addEventListener('click', function(e) {
    var dialog = Ti.UI.createAlertDialog({
        message: 'autoClose not set - default way',
        ok: 'Okay',
        title: 'autoClose'
    });
    dialog.show();
});
btn2.addEventListener('click', function(e) {
    var dialog = Ti.UI.createAlertDialog({
        message: 'AutoClose true',
        ok: 'Okay',
        title: 'autoClose',
        autoClose: true
    });
    dialog.show();
});
btn3.addEventListener('click', function(e) {
    var dialog = Ti.UI.createAlertDialog({
        cancel: 1,
        buttonNames: ['Confirm', 'Cancel', 'Help'],
        message: 'Click confirm and wait 3sec',
        ok: 'Okay',
        title: 'autoClose',
        autoClose: false
    });
    dialog.addEventListener('click', function(e) {
        Ti.API.info('e.index: ' + e.index);
        if (e.index == 0) {
            dialog.setMessage("closing...please wait 3sec")
            setTimeout(function() {
                dialog.hide();
            }, 3000)
        } else {
            alert("Click confirm and wait")
        }
    });
    dialog.show();
});
win.open();
* First button: default way * Second button: autoClose: true * Third button: autoClose: false (new way)

Comments

  1. Hans Knöchel 2017-01-29

    I have to be honest, I don't like that functionality and would propose to not add it to the SDK. And that because of the simple reason that (modal) alerts are supposed to be dismissed, so this would produce a UX leak that I'd like to prevent here. I'm open for discussion, but please consider to use a custom UI component to that special use-case.
  2. Michael Gangolf 2017-01-29

    I'll completely understand. It was a user request on tislack. The reason was that you are allowed to have inputs from the user in a dialog but you can't verify it without closing it when you click a button. Since it wasn't a big PR I'll did this. A workaround would already be to create a custom overlay view or window. This PR would just remove the need to create a custom window but stick to the AlertDialog to get the userdata. But a custom AlertDialog module would be also a good idea. Then its SDK independent
  3. Hans Knöchel 2017-01-29

    Thanks for the feedback. Resolving as Won't Fix based on the above reasons. Please feel free to patch the SDK anyway if this functionality is needed.

JSON Source