Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ios/Capacitor/Capacitor/CAPBridgeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Cordova
}

public fileprivate(set) var webView: WKWebView?
internal private(set) var statusBarBackgroundView: UIView?

public var isStatusBarVisible = true
public var statusBarStyle: UIStatusBarStyle = .default
Expand Down Expand Up @@ -44,6 +45,7 @@ import Cordova
let delegationHandler = WebViewDelegationHandler()
prepareWebView(with: configuration, assetHandler: assetHandler, delegationHandler: delegationHandler)
view = webView
installStatusBarBackground(using: configuration.backgroundColor ?? .systemBackground)
// create the bridge
capacitorBridge = CapacitorBridge(with: configuration,
delegate: self,
Expand Down Expand Up @@ -324,6 +326,23 @@ extension CAPBridgeViewController {
}
}

private func installStatusBarBackground(using color: UIColor) {
guard let webView else { return }

let background = UIView()
background.backgroundColor = color
background.isUserInteractionEnabled = false
background.translatesAutoresizingMaskIntoConstraints = false
webView.addSubview(background)
NSLayoutConstraint.activate([
background.topAnchor.constraint(equalTo: webView.topAnchor),
background.leadingAnchor.constraint(equalTo: webView.leadingAnchor),
background.trailingAnchor.constraint(equalTo: webView.trailingAnchor),
background.bottomAnchor.constraint(equalTo: webView.safeAreaLayoutGuide.topAnchor),
])
statusBarBackgroundView = background
}

private func updateBinaryVersion() {
guard isNewBinary else {
return
Expand Down
32 changes: 29 additions & 3 deletions ios/Capacitor/CapacitorTests/CapacitorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ import XCTest
class MockBridgeViewController: CAPBridgeViewController {
}

class BackgroundColorBridgeViewController: CAPBridgeViewController {
let descriptor: InstanceDescriptor

init(descriptor: InstanceDescriptor) {
self.descriptor = descriptor
super.init(nibName: nil, bundle: nil)
}

required init?(coder: NSCoder) {
descriptor = InstanceDescriptor.init()
super.init(coder: coder)
}

override func instanceDescriptor() -> InstanceDescriptor {
return descriptor
}
}

class MockAssetHandler: WebViewAssetHandler {
}

Expand All @@ -26,8 +44,16 @@ class CapacitorTests: XCTestCase {
bridge = MockBridge(with: InstanceConfiguration(with: descriptor, isDebug: true), delegate: MockBridgeViewController(), cordovaConfiguration: descriptor.cordovaConfiguration, assetHandler: MockAssetHandler(router: CapacitorRouter()), delegationHandler: MockDelegationHandler())
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
func testConfiguredBackgroundCoversStatusBarSafeArea() {
let descriptor = InstanceDescriptor.init()
descriptor.backgroundColor = .red
let controller = BackgroundColorBridgeViewController(descriptor: descriptor)

controller.loadView()

let statusBarBackground = controller.statusBarBackgroundView
XCTAssertEqual(statusBarBackground?.superview, controller.webView)
XCTAssertEqual(statusBarBackground?.backgroundColor, .red)
XCTAssertFalse(statusBarBackground?.isUserInteractionEnabled ?? true)
}
}