Fix drawing VC background flickering in dark mode

Closes #199
This commit is contained in:
Shadowfacts 2022-11-05 14:29:45 -04:00
parent 5bd7c0ad2b
commit 84cf755332
2 changed files with 30 additions and 8 deletions

View File

@ -14,6 +14,30 @@ protocol ComposeDrawingViewControllerDelegate: AnyObject {
func composeDrawingViewController(_ drawingController: ComposeDrawingViewController, saveDrawing drawing: PKDrawing) func composeDrawingViewController(_ drawingController: ComposeDrawingViewController, saveDrawing drawing: PKDrawing)
} }
class ComposeDrawingNavigationController: UINavigationController {
override var preferredStatusBarStyle: UIStatusBarStyle {
.darkContent
}
init(editing initialDrawing: PKDrawing, delegate: ComposeDrawingViewControllerDelegate) {
let vc = ComposeDrawingViewController(editing: initialDrawing)
vc.delegate = delegate
super.init(rootViewController: vc)
modalPresentationStyle = .fullScreen
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
overrideUserInterfaceStyle = .light
}
}
class ComposeDrawingViewController: UIViewController { class ComposeDrawingViewController: UIViewController {
weak var delegate: ComposeDrawingViewControllerDelegate? weak var delegate: ComposeDrawingViewControllerDelegate?
@ -26,7 +50,7 @@ class ComposeDrawingViewController: UIViewController {
private var toolPicker: PKToolPicker! private var toolPicker: PKToolPicker!
private var initialDrawing: PKDrawing? private var initialDrawing: PKDrawing?
init() { init() {
super.init(nibName: nil, bundle: nil) super.init(nibName: nil, bundle: nil)
} }
@ -45,7 +69,7 @@ class ComposeDrawingViewController: UIViewController {
super.viewDidLoad() super.viewDidLoad()
overrideUserInterfaceStyle = .light overrideUserInterfaceStyle = .light
navigationItem.title = NSLocalizedString("Draw", comment: "compose drawing screen title") navigationItem.title = NSLocalizedString("Draw", comment: "compose drawing screen title")
cancelBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelPressed)) cancelBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelPressed))
undoBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "arrow.uturn.left.circle"), style: .plain, target: self, action: #selector(undoPressed)) undoBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "arrow.uturn.left.circle"), style: .plain, target: self, action: #selector(undoPressed))
@ -63,7 +87,8 @@ class ComposeDrawingViewController: UIViewController {
canvasView.drawingPolicy = .anyInput canvasView.drawingPolicy = .anyInput
canvasView.minimumZoomScale = 0.5 canvasView.minimumZoomScale = 0.5
canvasView.maximumZoomScale = 2 canvasView.maximumZoomScale = 2
canvasView.backgroundColor = .systemBackground canvasView.backgroundColor = .white
canvasView.overrideUserInterfaceStyle = .light
canvasView.translatesAutoresizingMaskIntoConstraints = false canvasView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(canvasView) view.addSubview(canvasView)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
@ -74,6 +99,7 @@ class ComposeDrawingViewController: UIViewController {
]) ])
toolPicker = PKToolPicker() toolPicker = PKToolPicker()
toolPicker.overrideUserInterfaceStyle = .light
toolPicker.setVisible(true, forFirstResponder: canvasView) toolPicker.setVisible(true, forFirstResponder: canvasView)
toolPicker.addObserver(canvasView) toolPicker.addObserver(canvasView)
toolPicker.addObserver(self) toolPicker.addObserver(self)

View File

@ -360,11 +360,7 @@ extension ComposeHostingController: ComposeUIStateDelegate {
drawing = PKDrawing() drawing = PKDrawing()
} }
let drawingVC = ComposeDrawingViewController(editing: drawing) present(ComposeDrawingNavigationController(editing: drawing, delegate: self), animated: true)
drawingVC.delegate = self
let nav = UINavigationController(rootViewController: drawingVC)
nav.modalPresentationStyle = .fullScreen
present(nav, animated: true)
} }
} }