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

Support custom activities #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion ActivityView.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,30 @@ - (NSArray*)excludedActivitiesForKeys:(NSArray*)passedKeys {
return excludedActivities;
}

- (NSArray*)applicationActivitiesForKeys:(NSArray*)passedKeys
{
NSMutableArray *applicationActivities = [NSMutableArray new];

[passedKeys enumerateObjectsUsingBlock:^(NSString *activityName, NSUInteger idx, BOOL *stop) {
id customActivity = [self.bridge moduleForName:activityName];
if (!customActivity) {
RCTLogWarn(@"[ActivityView] Unknown application activity to add: %@", activityName);
return;
}
[applicationActivities addObject:customActivity];
}];

return applicationActivities;
}

RCT_EXPORT_METHOD(show:(NSDictionary *)args)
{
NSMutableArray *shareObject = [NSMutableArray array];
NSString *text = args[@"text"];
NSURL *url = args[@"url"];
NSString *imageUrl = args[@"imageUrl"];
NSArray *activitiesToExclude = args[@"exclude"];
NSArray *customActivitiesToAdd = args[@"customActivities"];
Copy link
Owner

Choose a reason for hiding this comment

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

Let's rename this to customActivitiesToInclude.

NSString *image = args[@"image"];
NSString *imageBase64 = args[@"imageBase64"];
NSData *imageData;
Expand Down Expand Up @@ -95,7 +112,9 @@ - (NSArray*)excludedActivitiesForKeys:(NSArray*)passedKeys {
[shareObject addObject: [UIImage imageWithData: imageData]];
}

UIActivityViewController *activityView = [[UIActivityViewController alloc] initWithActivityItems:shareObject applicationActivities:nil];
NSArray *applicationActivities = [self applicationActivitiesForKeys:customActivitiesToAdd];

UIActivityViewController *activityView = [[UIActivityViewController alloc] initWithActivityItems:shareObject applicationActivities:applicationActivities];

activityView.excludedActivityTypes = activitiesToExclude
? [self excludedActivitiesForKeys:activitiesToExclude]
Expand Down