Skip to content

Commit f7b72f2

Browse files
#33 iOS 10 updates
1 parent 0f18463 commit f7b72f2

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ This one has a custom `tintColor` (check the buttons):
3939

4040
<img src="screenshots/07-tintColor.PNG" width="350"/>
4141

42-
On iOS 10, you can use `barColor` and `tintColor`:
42+
On iOS 10, you can use `barColor` and `controlTintColor` as well
43+
(to make sure iOS 9 buttons are not white in the case, pass in a `tintColor` as well):
4344

4445
<img src="screenshots/08-barColor.PNG" width="350"/>
4546

@@ -74,8 +75,9 @@ function openUrl(url, readerMode) {
7475
animated: false, // default true, note that 'hide' will reuse this preference (the 'Done' button will always animate though)
7576
transition: 'curl', // (this only works in iOS 9.1/9.2 and lower) unless animated is false you can choose from: curl, flip, fade, slide (default)
7677
enterReaderModeIfAvailable: readerMode, // default false
77-
barColor: "#0000ff", // default is white (iOS 10 only)
78-
tintColor: "#ffffff" // default is ios blue
78+
tintColor: "#00ffff", // default is ios blue
79+
barColor: "#0000ff", // on iOS 10+ you can change the background color as well
80+
controlTintColor: "#ffffff" // on iOS 10+ you can override the default tintColor
7981
},
8082
// this success handler will be invoked for the lifecycle events 'opened', 'loaded' and 'closed'
8183
function(result) {

src/ios/SafariViewController.m

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,35 @@ - (void) show:(CDVInvokedUrlCommand*)command {
5151
}
5252

5353
NSString *tintColor = options[@"tintColor"];
54+
NSString *controlTintColor = options[@"controlTintColor"];
55+
NSString *barColor = options[@"barColor"];
56+
57+
// if only tintColor is set, use that as the controlTintColor for iOS 10
58+
if (barColor == nil && controlTintColor == nil) {
59+
controlTintColor = tintColor;
60+
} else if (tintColor == nil) {
61+
tintColor = controlTintColor;
62+
}
63+
5464
if (tintColor != nil) {
55-
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 // iOS 10.0 supported
56-
vc.preferredControlTintColor = [self colorFromHexString:options[@"tintColor"]];
57-
#else
58-
vc.view.tintColor = [self colorFromHexString:options[@"tintColor"]];
59-
#endif
65+
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 // iOS 10.0 supported (compile time)
66+
if (IsAtLeastiOSVersion(@"10")) { // iOS 10.0 supported (runtime)
67+
vc.preferredControlTintColor = [self colorFromHexString:controlTintColor];
68+
} else {
69+
vc.view.tintColor = [self colorFromHexString:tintColor];
70+
}
71+
#else
72+
vc.view.tintColor = [self colorFromHexString:tintColor];
73+
#endif
6074
}
6175

62-
NSString *barColor = options[@"barColor"];
63-
if (barColor != nil) {
64-
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 // iOS 10.0 supported
65-
vc.preferredBarTintColor = [self colorFromHexString:options[@"barColor"]];
66-
#endif
76+
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 // iOS 10.0 supported
77+
if (IsAtLeastiOSVersion(@"10")) { // iOS 10.0 supported (runtime)
78+
if (barColor != nil) {
79+
vc.preferredBarTintColor = [self colorFromHexString:barColor];
80+
}
6781
}
82+
#endif
6883

6984
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:@{@"event":@"opened"}];
7085
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];

0 commit comments

Comments
 (0)