Skip to content

Commit

Permalink
Fix Present SFSafariViewController from Top ViewController
Browse files Browse the repository at this point in the history
  • Loading branch information
cocojoe committed Sep 7, 2017
1 parent 8fb9d55 commit f93ca94
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion ios/A0Auth0.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ - (void)presentSafariWithURL:(NSURL *)url {
SFSafariViewController *controller = [[SFSafariViewController alloc] initWithURL:url];
controller.delegate = self;
[self terminateWithError:RCTMakeError(@"Only one Safari can be visible", nil, nil) dismissing:YES animated:NO];
[window.rootViewController presentViewController:controller animated:YES completion:nil];
[[self topViewControllerWithRootViewController: window.rootViewController] presentViewController:controller animated:YES completion:nil];
self.last = controller;
}

Expand Down Expand Up @@ -136,4 +136,22 @@ - (void)safariViewController:(SFSafariViewController *)controller didCompleteIni
[self terminateWithError:error dismissing:YES animated:YES];
}
}

# pragma mark - Utility

- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController {
if ([rootViewController isKindOfClass:[UITabBarController class]]) {
UITabBarController* tabBarController = (UITabBarController*)rootViewController;
return [self topViewControllerWithRootViewController:tabBarController.selectedViewController];
} else if ([rootViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController* navigationController = (UINavigationController*)rootViewController;
return [self topViewControllerWithRootViewController:navigationController.visibleViewController];
} else if (rootViewController.presentedViewController) {
UIViewController* presentedViewController = rootViewController.presentedViewController;
return [self topViewControllerWithRootViewController:presentedViewController];
} else {
return rootViewController;
}
}

@end

0 comments on commit f93ca94

Please sign in to comment.