Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TC-5357] Support destructive alert style #6697

Closed
wants to merge 4 commits into from

Conversation

hansemannn
Copy link
Collaborator

@hansemannn hansemannn changed the title TC-5357: Support destructive alert style [TC-5357] Support destructive alert style Mar 8, 2015
@@ -134,7 +136,7 @@ -(void)show:(id)args
NSString* btnName = [TiUtils stringValue:btn];
if (!IS_NULL_OR_NIL(btnName)) {
UIAlertAction* theAction = [UIAlertAction actionWithTitle:btnName
style:((curIndex == cancelIndex) ? UIAlertActionStyleCancel : UIAlertActionStyleDefault)
style:((curIndex == cancelIndex) ? UIAlertActionStyleCancel : (curIndex == destructiveIndex) ? UIAlertActionStyleDestructive :UIAlertActionStyleDefault)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is a bit confusing and not easy to follow due to the multiple ternary operators. If would be better to spread the out for clarity purposes, something like this:

UIAlertActionStyle style;
if (curIndex == cancelIndex) {
    style = UIAlertActionStyleCancel;
} else if (curIndex == destructiveIndex) {
    style = UIAlertActionStyleDestructive;
} else {
    style  = UIAlertActionStyleDefault;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if this is iOS 8 an above only, make sure you check for that with:

if ([TiUtils isIOS8OrGreater]) { ..... }

@pec1985
Copy link
Contributor

pec1985 commented May 11, 2015

PR reviewed, left a couple of comments.

@hansemannn
Copy link
Collaborator Author

Thank you! Comments are reasonable, will have a look at it!

@hansemannn
Copy link
Collaborator Author

Updated docs and code readability as well as a bounding-check like it is done with the cancel-button. I think the iOS 8 check is not necessary in this case, because the code is already in the conditional iOS 8 block to support the UIAlertController.

@pec1985
Copy link
Contributor

pec1985 commented May 11, 2015

One more thing... the destructive index is missing from the click event. For consistency, add it here as well fireClickEventWithAction:

NSMutableDictionary *event = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               NUMUINTEGER(indexOfAction),@"index",
                               [NSNumber numberWithInt:cancelIndex],@"cancel",
                               nil];

@hansemannn
Copy link
Collaborator Author

Added the destructive index and implemented a quick sample example code to test:

var win = Ti.UI.createWindow({
    backgroundColor: "#fff"
});

var button = Ti.UI.createButton({
    title: "Show destructive dialog"
});

var dialog = Ti.UI.createAlertDialog({
    title: "Proceed",
    message: "Do you really want to proceed?",
    destructive: 0,
    cancel: 1,
    buttonNames: ["Destructive", "Cancel", "Proceed"]
});

button.addEventListener("click", function() {
    dialog.show();
});

dialog.addEventListener("click", function(e) {
    Ti.API.info(e);
});

win.add(button);

win.open();

Output in the console:

[INFO] :   {
[INFO] :       bubbles = 1;
[INFO] :       cancel = 1;
[INFO] :       cancelBubble = 0;
[INFO] :       destructive = 0;
[INFO] :       index = 0;
[INFO] :       source = "[object TiUIAlertDialog]";
[INFO] :       type = click;
[INFO] :   }

@pec1985
Copy link
Contributor

pec1985 commented May 12, 2015

i have opened a new PR with your commits for Titanium master branch #6842

@pec1985
Copy link
Contributor

pec1985 commented May 12, 2015

There is one minor thing missing in the documentation. The since tag (for Ti SDK) and the osver for the iOS version. You can simple cherry pick from master since I already merged that

git cherry-pick cfcbc96

cfcbc96

@hansemannn
Copy link
Collaborator Author

Closing this outdated PR in favor of #6842

@hansemannn hansemannn closed this Oct 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants