Skip to content

Commit

Permalink
Generalize ActionSheetManager items URL
Browse files Browse the repository at this point in the history
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:

react-native-share/react-native-share#85

And I also need to be able to email/send on iMessage, etc with multiple URL resources.
Closes facebook#15475

Differential Revision: D6437807

Pulled By: hramos

fbshipit-source-id: 336c696c5633c0080904ca9306a38120e27f9173
  • Loading branch information
fxfactorial authored and bowerman0 committed Dec 5, 2017
1 parent a51e791 commit 312a12f
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions Libraries/ActionSheetIOS/RCTActionSheetManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,17 @@ - (CGRect)sourceRectInView:(UIView *)sourceView
if (message) {
[items addObject:message];
}
NSURL *URL = [RCTConvert NSURL:options[@"url"]];
if (URL) {
if ([URL.scheme.lowercaseString isEqualToString:@"data"]) {
NSArray<NSURL *> *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) {
Expand All @@ -146,13 +152,9 @@ - (CGRect)sourceRectInView:(UIView *)sourceView
}
[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];

Expand Down

0 comments on commit 312a12f

Please sign in to comment.