-
Notifications
You must be signed in to change notification settings - Fork 25
/
RCTBrowser.m
70 lines (57 loc) · 3.08 KB
/
RCTBrowser.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#import "RCTBrowser.h"
#import "TOWebViewController.h"
@implementation RCTBrowser
RCT_EXPORT_MODULE()
RCT_EXPORT_METHOD(presentUrl:(NSString *)url withOptions:(NSDictionary *)options) {
TOWebViewController *webVC = [[TOWebViewController alloc] initWithURLString:url];
[options enumerateKeysAndObjectsUsingBlock:^(NSString* key, id obj, BOOL *stop) {
if ([key isEqualToString:@"showLoadingBar"]) {
webVC.showLoadingBar = ([obj isEqual: @(YES)]);
} else if ([key isEqualToString:@"showUrlWhileLoading"]) {
webVC.showUrlWhileLoading = ([obj isEqual: @(YES)]);
} else if ([key isEqualToString:@"loadingBarTintColor"]) {
webVC.loadingBarTintColor = [RCTConvert UIColor:obj];
} else if ([key isEqualToString:@"navigationButtonsHidden"]) {
webVC.navigationButtonsHidden = ([obj isEqual: @(YES)]);
} else if ([key isEqualToString:@"showActionButton"]) {
webVC.showActionButton = ([obj isEqual: @(YES)]);
} else if ([key isEqualToString:@"showDoneButton"]) {
webVC.showDoneButton = ([obj isEqual: @(YES)]);
} else if ([key isEqualToString:@"doneButtonTitle"]) {
webVC.doneButtonTitle = (NSString*)obj;
} else if ([key isEqualToString:@"showPageTitles"]) {
webVC.showPageTitles = ([obj isEqual: @(YES)]);
} else if ([key isEqualToString:@"disableContextualPopupMenu"]) {
webVC.disableContextualPopupMenu = ([obj isEqual: @(YES)]);
} else if ([key isEqualToString:@"hideWebViewBoundaries"]) {
webVC.hideWebViewBoundaries = ([obj isEqual: @(YES)]);
} else if ([key isEqualToString:@"modalCompletionHandler"]) {
// TODO: turn this into a callback
} else if ([key isEqualToString:@"shouldStartLoadRequestHandler"]) {
// TODO: turn this into a callback
} else if ([key isEqualToString:@"buttonTintColor"]) {
webVC.buttonTintColor = [RCTConvert UIColor:obj];
} else if ([key isEqualToString:@"buttonBevelOpacity"]) {
// TODO: NOT YET IMPLEMENTED
}
}];
UIViewController *rootVC = [[UIApplication sharedApplication] keyWindow].rootViewController;
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:webVC];
[options enumerateKeysAndObjectsUsingBlock:^(NSString* key, id obj, BOOL *stop) {
if ([key isEqualToString:@"barTintColor"]) {
UIColor *color = [RCTConvert UIColor:obj];
nav.navigationBar.barTintColor = color;
nav.toolbar.barTintColor = color;
} else if ([key isEqualToString:@"titleTintColor"]) {
UIColor *color = [RCTConvert UIColor:obj];
nav.navigationBar.tintColor = color;
nav.toolbar.tintColor = color;
[nav.navigationBar setTitleTextAttributes:
@{NSForegroundColorAttributeName:color}];
}
}];
dispatch_async(dispatch_get_main_queue(), ^{
[rootVC presentViewController:nav animated:YES completion: nil];
});
}
@end