Skip to content

Commit

Permalink
fix(ios): make StatusBar Light style work on Dark mode (#1996)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Sep 26, 2019
1 parent 069b248 commit ab1ffd5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
8 changes: 8 additions & 0 deletions ios/Capacitor/Capacitor/CAPBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ enum BridgeError: Error {
}
return bridgeVC.preferredStatusBarStyle
}

@available(iOS 12.0, *)
public func getUserInterfaceStyle() -> UIUserInterfaceStyle {
guard let bridgeVC = self.viewController as? CAPBridgeViewController else {
return UIUserInterfaceStyle.unspecified
}
return bridgeVC.traitCollection.userInterfaceStyle
}

/**
* Get the last URL that triggered an open or continue activity event.
Expand Down
2 changes: 1 addition & 1 deletion ios/Capacitor/Capacitor/CAPBridgeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr
}
}
if let statusBarStyle = plist["UIStatusBarStyle"] as? String {
if (statusBarStyle != "UIStatusBarStyleDefault") {
if (statusBarStyle != "UIStatusBarStyleDefault" && statusBarStyle != "UIStatusBarStyleDarkContent") {
self.statusBarStyle = .lightContent
}
}
Expand Down
43 changes: 33 additions & 10 deletions ios/Capacitor/Capacitor/Plugins/StatusBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ public class CAPStatusBarPlugin: CAPPlugin {
if style == "DARK" {
bridge.setStatusBarStyle(.lightContent)
} else if style == "LIGHT" {
bridge.setStatusBarStyle(.default)
if #available(iOS 13.0, *) {
// TODO - use .darkContent instead of rawValue once Xcode 10 support is dropped
bridge.setStatusBarStyle(UIStatusBarStyle.init(rawValue: 3) ?? .default)
} else {
bridge.setStatusBarStyle(.default)
}
}
}

Expand All @@ -42,16 +47,34 @@ public class CAPStatusBarPlugin: CAPPlugin {
}

@objc func getInfo(_ call: CAPPluginCall) {
let style: String
if bridge.getStatusBarStyle() == .default {
style = "LIGHT"
} else {
style = "DARK"
DispatchQueue.main.async {
let style: String
if #available(iOS 13.0, *) {
switch self.bridge.getStatusBarStyle() {
case .default:
if self.bridge.getUserInterfaceStyle() == UIUserInterfaceStyle.dark {
style = "DARK"
} else {
style = "LIGHT"
}
case .lightContent:
style = "DARK"
default:
style = "LIGHT"
}
} else {
if self.bridge.getStatusBarStyle() == .lightContent {
style = "DARK"
} else {
style = "LIGHT"
}
}

call.success([
"visible": self.bridge.getStatusBarVisible(),
"style": style
])
}
call.success([
"visible": bridge.getStatusBarVisible(),
"style": style
])
}
}

0 comments on commit ab1ffd5

Please sign in to comment.