Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Present SFSafariViewController from Top ViewController #89

Merged
merged 1 commit into from
Sep 11, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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