Skip to content

Commit

Permalink
Fix ShareSheet crash on iOS 13 (#26429)
Browse files Browse the repository at this point in the history
Summary:
Currently on iOS 13 the app will crash if you:
- Open the share sheet
- Tap something like messages or photos
- Cancel the dialog
- Perform any other action

This is because `shareController.completionWithItemsHandler` is called when the dialog box is canceled and currently `failureCallback` or `successCallback` will always be called. In the situation above, `activityError` is `nil` so `successCallback` will be called even though `completed` is false. This leaves us in a state where the callback has been invoked but the ShareSheet is still active, meaning the success or error callback will be invoked again, leading to the crash.

This PR adds a check to make sure `completed` is true before calling `successCallback`. This way `successCallback` will only be called when the user has successfully completed an action and the ShareSheet is closed.

## Changelog

[iOS] [Fixed] - Fix crash in RCTActionSheetManager.m on iOS 13
Pull Request resolved: #26429

Test Plan:
- Saved an image successfully
- Opened and dismissed the `Photos` dialog multiple times without crashing

Differential Revision: D17369712

Pulled By: PeteTheHeat

fbshipit-source-id: 228b696243cd39fad1fa134f4412d95d845b1bc5
  • Loading branch information
tomtargosz authored and facebook-github-bot committed Sep 13, 2019
1 parent dbf070c commit a4fbb8e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Libraries/ActionSheetIOS/RCTActionSheetManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ - (void)presentViewController:(UIViewController *)alertController
shareController.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, __unused NSArray *returnedItems, NSError *activityError) {
if (activityError) {
failureCallback(activityError);
} else {
} else if (completed) {
successCallback(@[@(completed), RCTNullIfNil(activityType)]);
}
};
Expand Down

0 comments on commit a4fbb8e

Please sign in to comment.