From e4ae44e2ff46aba59403be4e85265eea65ad5924 Mon Sep 17 00:00:00 2001 From: Kevin Li Date: Sun, 2 Aug 2020 13:40:24 -0700 Subject: [PATCH] fixed bug on older iphones like 8 and below where a tap would be registered as a drag --- .../Views/ColorPaletteScene.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sources/ElegantColorPalette/Views/ColorPaletteScene.swift b/Sources/ElegantColorPalette/Views/ColorPaletteScene.swift index a4d621b..0a0e756 100644 --- a/Sources/ElegantColorPalette/Views/ColorPaletteScene.swift +++ b/Sources/ElegantColorPalette/Views/ColorPaletteScene.swift @@ -182,7 +182,10 @@ extension ColorPaletteScene { override func touchesMoved(_ touches: Set, with event: UIEvent?) { guard let activeNode = state.activeNode else { return } - guard let location = touches.first?.location(in: self) else { return } + guard let touch = touches.first else { return } + let location = touch.location(in: self) + let previous = touch.previousLocation(in: self) + guard location.distance(from: previous) != 0 else { return } guard isTouchWithinFrame(location) else { return } let offset = CGPoint(x: location.x - activeNode.position.x, @@ -282,3 +285,12 @@ private extension ColorPaletteScene { } } + +// MARK: - Extensions +private extension CGPoint { + + func distance(from point: CGPoint) -> CGFloat { + return hypot(point.x - x, point.y - y) + } + +}