@@ -34,92 +34,88 @@ - (instancetype)init
3434 failureCallback:(RCTResponseSenderBlock)failureCallback
3535 successCallback:(RCTResponseSenderBlock)successCallback)
3636{
37- dispatch_async (dispatch_get_main_queue (), ^{
38- UIActionSheet *actionSheet = [[UIActionSheet alloc ] init ];
37+ UIActionSheet *actionSheet = [[UIActionSheet alloc ] init ];
3938
40- actionSheet.title = options[@" title" ];
39+ actionSheet.title = options[@" title" ];
4140
42- for (NSString *option in options[@" options" ]) {
43- [actionSheet addButtonWithTitle: option];
44- }
41+ for (NSString *option in options[@" options" ]) {
42+ [actionSheet addButtonWithTitle: option];
43+ }
4544
46- if (options[@" destructiveButtonIndex" ]) {
47- actionSheet.destructiveButtonIndex = [options[@" destructiveButtonIndex" ] integerValue ];
48- }
49- if (options[@" cancelButtonIndex" ]) {
50- actionSheet.cancelButtonIndex = [options[@" cancelButtonIndex" ] integerValue ];
51- }
45+ if (options[@" destructiveButtonIndex" ]) {
46+ actionSheet.destructiveButtonIndex = [options[@" destructiveButtonIndex" ] integerValue ];
47+ }
48+ if (options[@" cancelButtonIndex" ]) {
49+ actionSheet.cancelButtonIndex = [options[@" cancelButtonIndex" ] integerValue ];
50+ }
5251
53- actionSheet.delegate = self;
52+ actionSheet.delegate = self;
5453
55- _callbacks[keyForInstance (actionSheet)] = successCallback;
54+ _callbacks[RCTKeyForInstance (actionSheet)] = successCallback;
5655
57- UIWindow *appWindow = [[[UIApplication sharedApplication ] delegate ] window ];
58- if (appWindow == nil ) {
59- RCTLogError (@" Tried to display action sheet but there is no application window. options: %@ " , options);
60- return ;
61- }
62- [actionSheet showInView: appWindow];
63- });
56+ UIWindow *appWindow = [[[UIApplication sharedApplication ] delegate ] window ];
57+ if (appWindow == nil ) {
58+ RCTLogError (@" Tried to display action sheet but there is no application window. options: %@ " , options);
59+ return ;
60+ }
61+ [actionSheet showInView: appWindow];
6462}
6563
6664RCT_EXPORT_METHOD (showShareActionSheetWithOptions:(NSDictionary *)options
6765 failureCallback:(RCTResponseSenderBlock)failureCallback
6866 successCallback:(RCTResponseSenderBlock)successCallback)
6967{
70- dispatch_async (dispatch_get_main_queue (), ^{
71- NSMutableArray *items = [NSMutableArray array ];
72- id message = options[@" message" ];
73- id url = options[@" url" ];
74- if ([message isKindOfClass: [NSString class ]]) {
75- [items addObject: message];
76- }
77- if ([url isKindOfClass: [NSString class ]]) {
78- [items addObject: [NSURL URLWithString: url]];
79- }
80- if ([items count ] == 0 ) {
81- failureCallback (@[@" No `url` or `message` to share" ]);
82- return ;
83- }
84- UIActivityViewController *share = [[UIActivityViewController alloc ] initWithActivityItems: items applicationActivities: nil ];
85- UIViewController *ctrl = [[[[UIApplication sharedApplication ] delegate ] window ] rootViewController ];
86- if ([share respondsToSelector: @selector (setCompletionWithItemsHandler: )]) {
87- share.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
88- if (activityError) {
89- failureCallback (@[[activityError localizedDescription ]]);
90- } else {
91- successCallback (@[@(completed), (activityType ?: [NSNull null ])]);
92- }
93- };
94- } else {
68+ NSMutableArray *items = [NSMutableArray array ];
69+ id message = options[@" message" ];
70+ id url = options[@" url" ];
71+ if ([message isKindOfClass: [NSString class ]]) {
72+ [items addObject: message];
73+ }
74+ if ([url isKindOfClass: [NSString class ]]) {
75+ [items addObject: [NSURL URLWithString: url]];
76+ }
77+ if ([items count ] == 0 ) {
78+ failureCallback (@[@" No `url` or `message` to share" ]);
79+ return ;
80+ }
81+ UIActivityViewController *share = [[UIActivityViewController alloc ] initWithActivityItems: items applicationActivities: nil ];
82+ UIViewController *ctrl = [[[[UIApplication sharedApplication ] delegate ] window ] rootViewController ];
83+ if ([share respondsToSelector: @selector (setCompletionWithItemsHandler: )]) {
84+ share.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
85+ if (activityError) {
86+ failureCallback (@[[activityError localizedDescription ]]);
87+ } else {
88+ successCallback (@[@(completed), (activityType ?: [NSNull null ])]);
89+ }
90+ };
91+ } else {
9592
9693#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0
9794
98- if (![UIActivityViewController instancesRespondToSelector: @selector (completionWithItemsHandler )]) {
99- // Legacy iOS 7 implementation
100- share.completionHandler = ^(NSString *activityType, BOOL completed) {
101- successCallback (@[@(completed), (activityType ?: [NSNull null ])]);
102- };
103- } else
95+ if (![UIActivityViewController instancesRespondToSelector: @selector (completionWithItemsHandler )]) {
96+ // Legacy iOS 7 implementation
97+ share.completionHandler = ^(NSString *activityType, BOOL completed) {
98+ successCallback (@[@(completed), (activityType ?: [NSNull null ])]);
99+ };
100+ } else
104101
105102#endif
106103
107- {
108- // iOS 8 version
109- share.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
110- successCallback (@[@(completed), (activityType ?: [NSNull null ])]);
111- };
112- }
104+ {
105+ // iOS 8 version
106+ share.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
107+ successCallback (@[@(completed), (activityType ?: [NSNull null ])]);
108+ };
113109 }
114- [ctrl presentViewController: share animated: YES completion: nil ];
115- }) ;
110+ }
111+ [ctrl presentViewController: share animated: YES completion: nil ] ;
116112}
117113
118114#pragma mark UIActionSheetDelegate Methods
119115
120116- (void )actionSheet : (UIActionSheet *)actionSheet clickedButtonAtIndex : (NSInteger )buttonIndex
121117{
122- NSString *key = keyForInstance (actionSheet);
118+ NSString *key = RCTKeyForInstance (actionSheet);
123119 RCTResponseSenderBlock callback = _callbacks[key];
124120 if (callback) {
125121 callback (@[@(buttonIndex)]);
@@ -133,7 +129,7 @@ - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger
133129
134130#pragma mark Private
135131
136- NS_INLINE NSString *keyForInstance (id instance)
132+ static NSString *RCTKeyForInstance (id instance)
137133{
138134 return [NSString stringWithFormat: @" %p " , instance];
139135}
0 commit comments