From bbe260bc9eb31a9157659b3e4dc6c13120fd406f Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 6 Jun 2021 21:33:17 -0400 Subject: [PATCH] Construct PKToolPicker ourselves --- .../ComposeDrawingViewController.swift | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/Tusker/Screens/Compose/ComposeDrawingViewController.swift b/Tusker/Screens/Compose/ComposeDrawingViewController.swift index a32589557c..29d89e7e31 100644 --- a/Tusker/Screens/Compose/ComposeDrawingViewController.swift +++ b/Tusker/Screens/Compose/ComposeDrawingViewController.swift @@ -23,6 +23,8 @@ class ComposeDrawingViewController: UIViewController { private(set) var undoBarButtonItem: UIBarButtonItem! private(set) var redoBarButtonItem: UIBarButtonItem! + private var toolPicker: PKToolPicker! + private var initialDrawing: PKDrawing? init() { @@ -70,25 +72,19 @@ class ComposeDrawingViewController: UIViewController { canvasView.topAnchor.constraint(equalTo: view.topAnchor), canvasView.bottomAnchor.constraint(equalTo: view.bottomAnchor) ]) - } - - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - // todo: should the PKToolPicker be owned by this VC or something else? - if let window = parent?.view.window, let toolPicker = PKToolPicker.shared(for: window) { - toolPicker.setVisible(true, forFirstResponder: canvasView) - toolPicker.addObserver(canvasView) - toolPicker.addObserver(self) - - updateLayout(for: toolPicker) - canvasView.becomeFirstResponder() - - // wait until the next run loop iteration so that the canvas view has become first responder and it's undo manager exists - DispatchQueue.main.async { - NotificationCenter.default.addObserver(self, selector: #selector(self.updateUndoRedoButtonState), name: .NSUndoManagerDidUndoChange, object: self.undoManager!) - NotificationCenter.default.addObserver(self, selector: #selector(self.updateUndoRedoButtonState), name: .NSUndoManagerDidRedoChange, object: self.undoManager!) - } + toolPicker = PKToolPicker() + toolPicker.setVisible(true, forFirstResponder: canvasView) + toolPicker.addObserver(canvasView) + toolPicker.addObserver(self) + + updateLayout(for: toolPicker) + canvasView.becomeFirstResponder() + + // wait until the next run loop iteration so that the canvas view has become first responder and it's undo manager exists + DispatchQueue.main.async { + NotificationCenter.default.addObserver(self, selector: #selector(self.updateUndoRedoButtonState), name: .NSUndoManagerDidUndoChange, object: self.undoManager!) + NotificationCenter.default.addObserver(self, selector: #selector(self.updateUndoRedoButtonState), name: .NSUndoManagerDidRedoChange, object: self.undoManager!) } }