From 2e424fb1133b2f304a99b7fc762c8ac97b46ad40 Mon Sep 17 00:00:00 2001 From: Edgar Aroutiounian Date: Wed, 29 Nov 2017 11:59:16 -0800 Subject: [PATCH] Generalize ActionSheetManager items URL Summary: Not ready but want to start conversation. (i.e. not sure if to change key name to `urls` from `url`) I want to be able to share more than 1 image at a time, the current code only lets one use one url, but the API allows for much more. Some places already make this an issue: https://github.com/EstebanFuentealba/react-native-share/issues/85 And I also need to be able to email/send on iMessage, etc with multiple URL resources. Closes https://github.com/facebook/react-native/pull/15475 Differential Revision: D6437807 Pulled By: hramos fbshipit-source-id: 336c696c5633c0080904ca9306a38120e27f9173 --- .../ActionSheetIOS/RCTActionSheetManager.m | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Libraries/ActionSheetIOS/RCTActionSheetManager.m b/Libraries/ActionSheetIOS/RCTActionSheetManager.m index 9f550f77a..708be80e0 100644 --- a/Libraries/ActionSheetIOS/RCTActionSheetManager.m +++ b/Libraries/ActionSheetIOS/RCTActionSheetManager.m @@ -133,11 +133,17 @@ RCT_EXPORT_METHOD(showShareActionSheetWithOptions:(NSDictionary *)options if (message) { [items addObject:message]; } - NSURL *URL = [RCTConvert NSURL:options[@"url"]]; - if (URL) { - if ([URL.scheme.lowercaseString isEqualToString:@"data"]) { + NSArray *URLS = [RCTConvert NSURLArray:options[@"url"]]; + + if (URLS.count == 0) { + RCTLogError(@"No `url` or `message` to share"); + return; + } + + for (NSURL *url in URLS) { + if ([url.scheme.lowercaseString isEqualToString:@"data"]) { NSError *error; - NSData *data = [NSData dataWithContentsOfURL:URL + NSData *data = [NSData dataWithContentsOfURL:url options:(NSDataReadingOptions)0 error:&error]; if (!data) { @@ -146,13 +152,9 @@ RCT_EXPORT_METHOD(showShareActionSheetWithOptions:(NSDictionary *)options } [items addObject:data]; } else { - [items addObject:URL]; + [items addObject:url]; } } - if (items.count == 0) { - RCTLogError(@"No `url` or `message` to share"); - return; - } UIActivityViewController *shareController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];