Document Controls: adds dark mode button

This commit is contained in:
James Magahern
2021-02-15 22:47:02 -08:00
parent 2b5475d7f8
commit 00e50b5bda
8 changed files with 52 additions and 27 deletions

View File

@@ -41,6 +41,14 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
private var commandKeyHeld: Bool = false
private var darkModeEnabled: Bool {
get { tab.bridge.darkModeEnabled }
set {
tab.bridge.darkModeEnabled = newValue
toolbarController.darkModeEnabled = newValue
}
}
override var preferredStatusBarStyle: UIStatusBarStyle { .lightContent }
init() {
@@ -124,8 +132,7 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
// Dark mode button
toolbarController.darkModeButton.addAction(UIAction(handler: { [unowned self] _ in
self.tab.bridge.darkModeEnabled = !self.tab.bridge.darkModeEnabled
self.toolbarController.darkModeEnabled = self.tab.bridge.darkModeEnabled
self.darkModeEnabled = !self.darkModeEnabled
}), for: .touchUpInside)
// Tabs button
@@ -192,7 +199,7 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
// Font size adjust
toolbarController.urlBar.documentButton.addAction(UIAction(handler: { [unowned self] _ in
let documentControls = DocumentControlViewController()
let documentControls = DocumentControlViewController(darkModeEnabled: tab.bridge.darkModeEnabled)
documentControls.modalPresentationStyle = .popover
documentControls.popoverPresentationController?.permittedArrowDirections = [ .down, .up ]
documentControls.popoverPresentationController?.sourceView = toolbarController.urlBar.documentButton
@@ -257,6 +264,12 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
}
}, for: .touchUpInside)
// Dark mode
documentControls.darkModeView.addAction(UIAction { [unowned self] _ in
self.darkModeEnabled = !self.darkModeEnabled
documentControls.dismiss(animated: true, completion: nil)
}, for: .touchUpInside)
present(documentControls, animated: true, completion: nil)
}), for: .touchUpInside)