From 782696ac0e2557a206cc6e4f100ec4f205d53fff Mon Sep 17 00:00:00 2001 From: Steven Goff Date: Thu, 11 May 2017 12:11:30 -0500 Subject: [PATCH 1/3] Add support for an array of destructiveButtonIndexes --- Libraries/ActionSheetIOS/ActionSheetIOS.js | 1 + Libraries/ActionSheetIOS/RCTActionSheetManager.m | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Libraries/ActionSheetIOS/ActionSheetIOS.js b/Libraries/ActionSheetIOS/ActionSheetIOS.js index b135a23e5fc998..287a38738eb094 100644 --- a/Libraries/ActionSheetIOS/ActionSheetIOS.js +++ b/Libraries/ActionSheetIOS/ActionSheetIOS.js @@ -28,6 +28,7 @@ const ActionSheetIOS = { * - `options` (array of strings) - a list of button titles (required) * - `cancelButtonIndex` (int) - index of cancel button in `options` * - `destructiveButtonIndex` (int) - index of destructive button in `options` + * - `destructiveButtonIndexes` (array of ints) - indexes of destructive button in `options` * - `title` (string) - a title to show above the action sheet * - `message` (string) - a message to show below the title * diff --git a/Libraries/ActionSheetIOS/RCTActionSheetManager.m b/Libraries/ActionSheetIOS/RCTActionSheetManager.m index cd5d5719ff769c..e9fc98962ba0c0 100644 --- a/Libraries/ActionSheetIOS/RCTActionSheetManager.m +++ b/Libraries/ActionSheetIOS/RCTActionSheetManager.m @@ -64,6 +64,7 @@ - (CGRect)sourceRectInView:(UIView *)sourceView NSString *message = [RCTConvert NSString:options[@"message"]]; NSArray *buttons = [RCTConvert NSStringArray:options[@"options"]]; NSInteger destructiveButtonIndex = options[@"destructiveButtonIndex"] ? [RCTConvert NSInteger:options[@"destructiveButtonIndex"]] : -1; + NSArray *destructiveButtonIndexes = [RCTConvert NSArray:options[@"destructiveButtonIndexes"]]; NSInteger cancelButtonIndex = options[@"cancelButtonIndex"] ? [RCTConvert NSInteger:options[@"cancelButtonIndex"]] : -1; UIViewController *controller = RCTPresentedViewController(); @@ -90,7 +91,7 @@ - (CGRect)sourceRectInView:(UIView *)sourceView NSInteger index = 0; for (NSString *option in buttons) { UIAlertActionStyle style = UIAlertActionStyleDefault; - if (index == destructiveButtonIndex) { + if (index == destructiveButtonIndex || [destructiveButtonIndexes containsObject:@(index)]) style = UIAlertActionStyleDestructive; } else if (index == cancelButtonIndex) { style = UIAlertActionStyleCancel; From 6b347a44d50baec7c73ee208b7238330e70c8a6a Mon Sep 17 00:00:00 2001 From: Steven Goff Date: Thu, 11 May 2017 12:57:13 -0500 Subject: [PATCH 2/3] Fix missing { typo --- Libraries/ActionSheetIOS/RCTActionSheetManager.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/ActionSheetIOS/RCTActionSheetManager.m b/Libraries/ActionSheetIOS/RCTActionSheetManager.m index e9fc98962ba0c0..58f07a3e4c30fd 100644 --- a/Libraries/ActionSheetIOS/RCTActionSheetManager.m +++ b/Libraries/ActionSheetIOS/RCTActionSheetManager.m @@ -91,7 +91,7 @@ - (CGRect)sourceRectInView:(UIView *)sourceView NSInteger index = 0; for (NSString *option in buttons) { UIAlertActionStyle style = UIAlertActionStyleDefault; - if (index == destructiveButtonIndex || [destructiveButtonIndexes containsObject:@(index)]) + if (index == destructiveButtonIndex || [destructiveButtonIndexes containsObject:@(index)]) { style = UIAlertActionStyleDestructive; } else if (index == cancelButtonIndex) { style = UIAlertActionStyleCancel; From cb83d62bfd644a1a9a9e7e205caa51dc2a7d68bf Mon Sep 17 00:00:00 2001 From: Noah Malmed Date: Tue, 10 Oct 2017 13:06:40 -0500 Subject: [PATCH 3/3] Overload destructiveButtonIndex for int and array --- Libraries/ActionSheetIOS/ActionSheetIOS.js | 3 +-- Libraries/ActionSheetIOS/RCTActionSheetManager.m | 11 ++++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Libraries/ActionSheetIOS/ActionSheetIOS.js b/Libraries/ActionSheetIOS/ActionSheetIOS.js index 287a38738eb094..5f7752ed9c8c38 100644 --- a/Libraries/ActionSheetIOS/ActionSheetIOS.js +++ b/Libraries/ActionSheetIOS/ActionSheetIOS.js @@ -27,8 +27,7 @@ const ActionSheetIOS = { * * - `options` (array of strings) - a list of button titles (required) * - `cancelButtonIndex` (int) - index of cancel button in `options` - * - `destructiveButtonIndex` (int) - index of destructive button in `options` - * - `destructiveButtonIndexes` (array of ints) - indexes of destructive button in `options` + * - `destructiveButtonIndex` (int or array of ints) - index or indices of destructive buttons in `options` * - `title` (string) - a title to show above the action sheet * - `message` (string) - a message to show below the title * diff --git a/Libraries/ActionSheetIOS/RCTActionSheetManager.m b/Libraries/ActionSheetIOS/RCTActionSheetManager.m index 58f07a3e4c30fd..c806f4e37b6a8c 100644 --- a/Libraries/ActionSheetIOS/RCTActionSheetManager.m +++ b/Libraries/ActionSheetIOS/RCTActionSheetManager.m @@ -63,9 +63,14 @@ - (CGRect)sourceRectInView:(UIView *)sourceView NSString *title = [RCTConvert NSString:options[@"title"]]; NSString *message = [RCTConvert NSString:options[@"message"]]; NSArray *buttons = [RCTConvert NSStringArray:options[@"options"]]; - NSInteger destructiveButtonIndex = options[@"destructiveButtonIndex"] ? [RCTConvert NSInteger:options[@"destructiveButtonIndex"]] : -1; - NSArray *destructiveButtonIndexes = [RCTConvert NSArray:options[@"destructiveButtonIndexes"]]; NSInteger cancelButtonIndex = options[@"cancelButtonIndex"] ? [RCTConvert NSInteger:options[@"cancelButtonIndex"]] : -1; + NSArray *destructiveButtonIndices; + if ([options[@"destructiveButtonIndex"] isKindOfClass:[NSArray class]]) { + destructiveButtonIndices = [RCTConvert NSArray:options[@"destructiveButtonIndex"]]; + } else { + NSNumber *destructiveButtonIndex = options[@"destructiveButtonIndex"] ? [RCTConvert NSNumber:options[@"destructiveButtonIndex"]] : @-1; + destructiveButtonIndices = @[destructiveButtonIndex]; + } UIViewController *controller = RCTPresentedViewController(); @@ -91,7 +96,7 @@ - (CGRect)sourceRectInView:(UIView *)sourceView NSInteger index = 0; for (NSString *option in buttons) { UIAlertActionStyle style = UIAlertActionStyleDefault; - if (index == destructiveButtonIndex || [destructiveButtonIndexes containsObject:@(index)]) { + if ([destructiveButtonIndices containsObject:@(index)]) { style = UIAlertActionStyleDestructive; } else if (index == cancelButtonIndex) { style = UIAlertActionStyleCancel;