From f35fbc2a145f0097142d08920e141ea0cce2c31c Mon Sep 17 00:00:00 2001 From: Param Aggarwal Date: Tue, 15 Sep 2015 11:28:24 -0700 Subject: [PATCH] Fixes consistent crash on iPad with iOS 8 while sharing. Summary: (Fixes #1890, #2395, #2604.) Usage: ``` ActionSheetIOS.showShareActionSheetWithOptions({ anchor: React.findNodeHandle(this.refs.share), message: "React Native", url: "https://github.com/facebook/react-native" }, (e)=>{ console.log('shared'); }, (e)=>{console.log('dismissed'); }); ``` Screenshot on iPad with iOS 8: screen shot 2015-09-09 at 8 50 26 am If the `anchor` is not specified, it will centre the popup on screen without arrows: ![centered](https://cloud.githubusercontent.com/assets/543981/9752612/10c87c6a-56d0-11e5-8c59-fcbf64a36f9c.png) Closes https://github.com/facebook/react-native/pull/2610 Reviewed By: @nicklockwood Differential Revision: D2439533 Pulled By: @javache --- .../ActionSheetIOS/RCTActionSheetManager.m | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Libraries/ActionSheetIOS/RCTActionSheetManager.m b/Libraries/ActionSheetIOS/RCTActionSheetManager.m index ecd522cee..34a791520 100644 --- a/Libraries/ActionSheetIOS/RCTActionSheetManager.m +++ b/Libraries/ActionSheetIOS/RCTActionSheetManager.m @@ -12,6 +12,8 @@ #import "RCTConvert.h" #import "RCTLog.h" #import "RCTUtils.h" +#import "RCTBridge.h" +#import "RCTUIManager.h" @interface RCTActionSheetManager () @@ -110,6 +112,24 @@ RCT_EXPORT_METHOD(showShareActionSheetWithOptions:(NSDictionary *)options }; } + /* + * The `anchor` option takes a view to set as the anchor for the share + * popup to point to, on iPads running iOS 8. If it is not passed, it + * defaults to centering the share popup on screen without any arrows. + */ + if ([share respondsToSelector:@selector(popoverPresentationController)]) { + share.popoverPresentationController.sourceView = ctrl.view; + NSNumber *anchorViewTag = [RCTConvert NSNumber:options[@"anchor"]]; + if (anchorViewTag) { + UIView *anchorView = [self.bridge.uiManager viewForReactTag:anchorViewTag]; + share.popoverPresentationController.sourceRect = [anchorView convertRect:anchorView.bounds toView:ctrl.view]; + } else { + CGRect sourceRect = CGRectMake(ctrl.view.center.x, ctrl.view.center.y, 1, 1); + share.popoverPresentationController.sourceRect = sourceRect; + share.popoverPresentationController.permittedArrowDirections = 0; + } + } + [ctrl presentViewController:share animated:YES completion:nil]; }