diff --git a/ios/Capacitor/Capacitor/CAPBridge.swift b/ios/Capacitor/Capacitor/CAPBridge.swift index 691fc26609..91842bdefe 100644 --- a/ios/Capacitor/Capacitor/CAPBridge.swift +++ b/ios/Capacitor/Capacitor/CAPBridge.swift @@ -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. diff --git a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift index 22a3fe204c..b103df6af4 100644 --- a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift +++ b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift @@ -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 } } diff --git a/ios/Capacitor/Capacitor/Plugins/StatusBar.swift b/ios/Capacitor/Capacitor/Plugins/StatusBar.swift index c2df127ece..4b60bdbafc 100644 --- a/ios/Capacitor/Capacitor/Plugins/StatusBar.swift +++ b/ios/Capacitor/Capacitor/Plugins/StatusBar.swift @@ -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) + } } } @@ -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 - ]) } }