Skip to content

Commit

Permalink
fix: Share UI will be closed if the selected app was "cancelled" (#973)
Browse files Browse the repository at this point in the history
Side effect: Share UI will be closed if the selected app was "cancelled", instead of causing a crash due to duplicate callback calls.

Co-authored-by: Cristiano Coelho <cristianocca@hotmail.com>
  • Loading branch information
cristianoccazinsp and cristianocca committed Feb 25, 2021
1 parent 94b7332 commit a4478f2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ios/RNShare.m
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,23 @@ - (NSDictionary *)constantsToExport
shareController.excludedActivityTypes = excludedActivityTypes;
}

__weak UIActivityViewController* weakShareController = shareController;
shareController.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, __unused NSArray *returnedItems, NSError *activityError) {

// always dismiss since this may be called from cancelled shares
// but the share menu would remain open, and our callback would fire again on close
[controller dismissViewControllerAnimated:true completion:nil];

if (activityError) {
[controller dismissViewControllerAnimated:true completion:nil];
failureCallback(activityError);
} else {
successCallback(@[@(completed), RCTNullIfNil(activityType)]);
}

// clear the completion handler to prevent cycles
if(weakShareController){
weakShareController.completionWithItemsHandler = nil;
}
};

shareController.modalPresentationStyle = UIModalPresentationPopover;
Expand Down

0 comments on commit a4478f2

Please sign in to comment.