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] iOS - Support destructive alert style #6842

Merged
merged 5 commits into from
May 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions apidoc/Titanium/UI/AlertDialog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,17 @@ properties:
On iOS and Mobile Web, set to `-1` to disable the cancel option.
type: Number
default: undefined (Android), -1 (iOS, Mobile Web)


- name: destructive
summary: Index to define the destructive button.
platforms: [iphone, ipad]
description: |
Note that this property is only available on iOS 8 or above. Setting to -1 disables this option.
type: Number
default: -1
since: 3.5.0
osver: {ios: {min: "8.0"}}

- name: message
summary: Dialog message.
type: String
Expand All @@ -196,7 +206,7 @@ properties:
<Titanium.UI.iPhone.AlertDialogStyle>. Using styles other than default one can break
your dialog layout if more than two buttons used. All styles can handle up to two
buttons comfortably, except for default style can handle up to six buttons when `title`
and `message` is empty or not given. Note that this property available on
and `message` is empty or not given. Note that this property is only available on
iOS SDK 5 or above.
type: Number
default: <Titanium.UI.iPhone.AlertDialogStyle.DEFAULT>
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/TiUIAlertDialogProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
UIAlertController* alertController;
BOOL persistentFlag;
int cancelIndex;
int destructiveIndex;
int style;
}

Expand Down
21 changes: 20 additions & 1 deletion iphone/Classes/TiUIAlertDialogProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,16 @@ -(void)show:(id)args
}

cancelIndex = [TiUtils intValue:[self valueForKey:@"cancel"] def:-1];
destructiveIndex = [TiUtils intValue:[self valueForKey:@"destructive"] def:-1];

if (cancelIndex >= [buttonNames count]) {
cancelIndex = -1;
}

if (destructiveIndex >= [buttonNames count]) {
destructiveIndex = -1;
}

style = [TiUtils intValue:[self valueForKey:@"style"] def:UIAlertViewStyleDefault];

if ([TiUtils isIOS8OrGreater]) {
Expand All @@ -128,12 +134,24 @@ -(void)show:(id)args
message:[TiUtils stringValue:[self valueForKey:@"message"]]
preferredStyle:UIAlertControllerStyleAlert] retain];
int curIndex = 0;

//Configure the Buttons
for (id btn in buttonNames) {
NSString* btnName = [TiUtils stringValue:btn];
if (!IS_NULL_OR_NIL(btnName)) {

UIAlertActionStyle alertActionStyle;

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

UIAlertAction* theAction = [UIAlertAction actionWithTitle:btnName
style:((curIndex == cancelIndex) ? UIAlertActionStyleCancel : UIAlertActionStyleDefault)
style:alertActionStyle
handler:^(UIAlertAction * action){
[self fireClickEventWithAction:action];
}];
Expand Down Expand Up @@ -198,6 +216,7 @@ -(void) fireClickEventWithAction:(UIAlertAction*)theAction
NSMutableDictionary *event = [NSMutableDictionary dictionaryWithObjectsAndKeys:
NUMUINTEGER(indexOfAction),@"index",
[NSNumber numberWithInt:cancelIndex],@"cancel",
[NSNumber numberWithInt:destructiveIndex],@"destructive",
nil];


Expand Down