-
Notifications
You must be signed in to change notification settings - Fork 12
/
RCTSFSafariViewController.m
51 lines (38 loc) · 1.89 KB
/
RCTSFSafariViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#import "RCTSFSafariViewController.h"
@implementation RCTSFSafariViewController
@synthesize bridge = _bridge;
RCT_EXPORT_MODULE();
- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller {
[self.bridge.eventDispatcher sendAppEventWithName:@"SFSafariViewControllerDismissed" body:nil];
}
RCT_EXPORT_METHOD(openURL:(NSString *)urlString params:(NSDictionary *)params) {
NSURL *url = [[NSURL alloc] initWithString:urlString];
UIViewController *rootViewController = [[[UIApplication sharedApplication] delegate] window].rootViewController;
while(rootViewController.presentedViewController) {
rootViewController = rootViewController.presentedViewController;
}
SFSafariViewController *safariViewController = [[SFSafariViewController alloc] initWithURL:url];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:safariViewController];
[navigationController setNavigationBarHidden:YES animated:NO];
safariViewController.delegate = self;
if ([params objectForKey:@"tintColor"]) {
UIColor *tintColor = [RCTConvert UIColor:params[@"tintColor"]];
if([safariViewController respondsToSelector:@selector(setPreferredControlTintColor:)]) {
safariViewController.preferredControlTintColor = tintColor;
} else {
safariViewController.view.tintColor = tintColor;
}
}
dispatch_async(dispatch_get_main_queue(), ^{
[rootViewController presentViewController:navigationController animated:YES completion:^{
[self.bridge.eventDispatcher sendDeviceEventWithName:@"SFSafariViewControllerDidLoad" body:nil];
}];
});
}
RCT_EXPORT_METHOD(close) {
dispatch_async(dispatch_get_main_queue(), ^{
UIViewController *rootViewController = [[[UIApplication sharedApplication] delegate] window].rootViewController;
[rootViewController dismissViewControllerAnimated:YES completion:nil];
});
}
@end