Skip to content

Commit 736ea84

Browse files
author
DependencyBot
committed
Ensure that it always raises a PlatformException if argument is required, but not given
1 parent 758f52a commit 736ea84

File tree

1 file changed

+37
-23
lines changed

1 file changed

+37
-23
lines changed

packages/share_plus/share_plus/ios/Classes/FLTSharePlusPlugin.m

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -261,27 +261,13 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
261261

262262
UIViewController *topViewController =
263263
TopViewControllerForViewController(RootViewController());
264-
BOOL isCoordinateSpaceOfSourceView =
265-
CGRectContainsRect(topViewController.view.frame, originRect);
266-
if (!isCoordinateSpaceOfSourceView) {
267-
result([FlutterError
268-
errorWithCode:@"error"
269-
message:[NSString
270-
stringWithFormat:
271-
@"sharePositionOrigin: %@ must be within "
272-
@"coordinate space of source view: %@",
273-
NSStringFromCGRect(originRect),
274-
NSStringFromCGRect(
275-
topViewController.view.bounds)]
276-
details:nil]);
277-
return;
278-
}
279264

280265
[self shareText:shareText
281266
subject:shareSubject
282267
withController:topViewController
283268
atSource:originRect
284-
toResult:withResult ? result : nil];
269+
toResult:result
270+
withResult:withResult];
285271
if (!withResult)
286272
result(nil);
287273
} else if ([@"shareFiles" isEqualToString:call.method] ||
@@ -315,7 +301,8 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
315301
withText:text
316302
withController:topViewController
317303
atSource:originRect
318-
toResult:withResult ? result : nil];
304+
toResult:result
305+
withResult:withResult];
319306
if (!withResult)
320307
result(nil);
321308
} else {
@@ -328,7 +315,8 @@ + (void)share:(NSArray *)shareItems
328315
withSubject:(NSString *)subject
329316
withController:(UIViewController *)controller
330317
atSource:(CGRect)origin
331-
toResult:(FlutterResult)result {
318+
toResult:(FlutterResult)result
319+
withResult:(BOOL)withResult {
332320
UIActivityViewSuccessController *activityViewController =
333321
[[UIActivityViewSuccessController alloc] initWithActivityItems:shareItems
334322
applicationActivities:nil];
@@ -340,10 +328,32 @@ + (void)share:(NSArray *)shareItems
340328

341329
activityViewController.popoverPresentationController.sourceView =
342330
controller.view;
331+
BOOL isCoordinateSpaceOfSourceView =
332+
CGRectContainsRect(controller.view.frame, origin);
333+
334+
// If device is e.g. an iPad then hasPopoverPresentationController is true
335+
BOOL hasPopoverPresentationController =
336+
[activityViewController popoverPresentationController] != NULL;
337+
if (hasPopoverPresentationController &&
338+
(!isCoordinateSpaceOfSourceView || CGRectIsEmpty(origin))) {
339+
NSString *sharePositionIssue = [NSString
340+
stringWithFormat:
341+
@"sharePositionOrigin: argument must be set, %@ must be non-zero "
342+
@"and within coordinate space of source view: %@",
343+
NSStringFromCGRect(origin),
344+
NSStringFromCGRect(controller.view.bounds)];
345+
346+
result([FlutterError errorWithCode:@"error"
347+
message:sharePositionIssue
348+
details:nil]);
349+
return;
350+
}
351+
343352
if (!CGRectIsEmpty(origin)) {
344353
activityViewController.popoverPresentationController.sourceRect = origin;
345354
}
346-
if (result) {
355+
356+
if (withResult) {
347357
UIActivityViewSuccessCompanion *companion =
348358
[[UIActivityViewSuccessCompanion alloc] initWithResult:result];
349359
activityViewController.companion = companion;
@@ -363,7 +373,8 @@ + (void)shareText:(NSString *)shareText
363373
subject:(NSString *)subject
364374
withController:(UIViewController *)controller
365375
atSource:(CGRect)origin
366-
toResult:(FlutterResult)result {
376+
toResult:(FlutterResult)result
377+
withResult:(BOOL)withResult {
367378
NSObject *data = [[NSURL alloc] initWithString:shareText];
368379
if (data == nil) {
369380
data = [[SharePlusData alloc] initWithSubject:subject text:shareText];
@@ -372,7 +383,8 @@ + (void)shareText:(NSString *)shareText
372383
withSubject:subject
373384
withController:controller
374385
atSource:origin
375-
toResult:result];
386+
toResult:result
387+
withResult:withResult];
376388
}
377389

378390
+ (void)shareFiles:(NSArray *)paths
@@ -381,7 +393,8 @@ + (void)shareFiles:(NSArray *)paths
381393
withText:(NSString *)text
382394
withController:(UIViewController *)controller
383395
atSource:(CGRect)origin
384-
toResult:(FlutterResult)result {
396+
toResult:(FlutterResult)result
397+
withResult:(BOOL)withResult {
385398
NSMutableArray *items = [[NSMutableArray alloc] init];
386399

387400
for (int i = 0; i < [paths count]; i++) {
@@ -403,7 +416,8 @@ + (void)shareFiles:(NSArray *)paths
403416
withSubject:subject
404417
withController:controller
405418
atSource:origin
406-
toResult:result];
419+
toResult:result
420+
withResult:withResult];
407421
}
408422

409423
@end

0 commit comments

Comments
 (0)