diff --git a/SignalMessaging/Views/ImageEditor/ImageEditorBrushViewController.swift b/SignalMessaging/Views/ImageEditor/ImageEditorBrushViewController.swift index 6c79fde1b..4f9e5ccfd 100644 --- a/SignalMessaging/Views/ImageEditor/ImageEditorBrushViewController.swift +++ b/SignalMessaging/Views/ImageEditor/ImageEditorBrushViewController.swift @@ -127,7 +127,7 @@ public class ImageEditorBrushViewController: OWSViewController { private var currentStrokeSamples = [ImageEditorStrokeItem.StrokeSample]() @objc - public func handleBrushGesture(_ gestureRecognizer: UIGestureRecognizer) { + public func handleBrushGesture(_ gestureRecognizer: ImageEditorPanGestureRecognizer) { AssertIsOnMainThread() let removeCurrentStroke = { @@ -137,10 +137,9 @@ public class ImageEditorBrushViewController: OWSViewController { self.currentStroke = nil self.currentStrokeSamples.removeAll() } - let tryToAppendStrokeSample = { + let tryToAppendStrokeSample = { (locationInView: CGPoint) in let view = self.canvasView.gestureReferenceView let viewBounds = view.bounds - let locationInView = gestureRecognizer.location(in: view) let newSample = ImageEditorCanvasView.locationImageUnit(forLocationInView: locationInView, viewBounds: viewBounds, model: self.model, @@ -162,14 +161,22 @@ public class ImageEditorBrushViewController: OWSViewController { case .began: removeCurrentStroke() - tryToAppendStrokeSample() + // Apply the location history of the gesture so that the stroke reflects + // the touch's movement before the gesture recognized. + for location in gestureRecognizer.locations { + tryToAppendStrokeSample(location) + } + + let locationInView = gestureRecognizer.location(in: canvasView.gestureReferenceView) + tryToAppendStrokeSample(locationInView) let stroke = ImageEditorStrokeItem(color: strokeColor, unitSamples: currentStrokeSamples, unitStrokeWidth: unitStrokeWidth) model.append(item: stroke) currentStroke = stroke case .changed, .ended: - tryToAppendStrokeSample() + let locationInView = gestureRecognizer.location(in: canvasView.gestureReferenceView) + tryToAppendStrokeSample(locationInView) guard let lastStroke = self.currentStroke else { owsFailDebug("Missing last stroke.") diff --git a/SignalMessaging/Views/ImageEditor/ImageEditorPanGestureRecognizer.swift b/SignalMessaging/Views/ImageEditor/ImageEditorPanGestureRecognizer.swift index 3f5cc39ee..835df3b93 100644 --- a/SignalMessaging/Views/ImageEditor/ImageEditorPanGestureRecognizer.swift +++ b/SignalMessaging/Views/ImageEditor/ImageEditorPanGestureRecognizer.swift @@ -13,7 +13,12 @@ public class ImageEditorPanGestureRecognizer: UIPanGestureRecognizer { public weak var referenceView: UIView? - public var locationStart: CGPoint? + // Capture the location history of this gesture. + public var locations = [CGPoint]() + + public var locationStart: CGPoint? { + return locations.first + } // MARK: - Touch Handling @@ -25,12 +30,23 @@ public class ImageEditorPanGestureRecognizer: UIPanGestureRecognizer { owsFailDebug("Missing view") return } - locationStart = self.location(in: referenceView) + locations.append(location(in: referenceView)) + } + + @objc + public override func touchesMoved(_ touches: Set, with event: UIEvent) { + super.touchesMoved(touches, with: event) + + guard let referenceView = referenceView else { + owsFailDebug("Missing view") + return + } + locations.append(location(in: referenceView)) } public override func reset() { super.reset() - locationStart = nil + locations.removeAll() } }