Skip to content

Commit 18bee1c

Browse files
committed
Fix FingerUp causing UITouch to end in start location
1 parent 973901f commit 18bee1c

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

Sources/Hammer/EventGenerator/EventGenerator+Hand/EventGenerator+Hand.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ extension EventGenerator {
498498
throw HammerError.touchForFingerDoesNotExist(index: finger.fingerIndex)
499499
}
500500

501+
try self.activeTouches.update(finger: finger, forIdentifier: existingIdentifier)
501502
return existingIdentifier
502503
case .ended, .cancelled:
503504
guard let existingIdentifier = existingIdentifier else {

Sources/Hammer/Utilties/TouchStorage.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,9 @@ struct TouchStorage {
5454
self.stylusStore = nil
5555
}
5656
}
57+
58+
mutating func update(finger: FingerInfo, forIdentifier identifier: UInt32) throws {
59+
self.fingerStore.removeAll { $0.identifier == identifier }
60+
self.fingerStore.append((finger, identifier))
61+
}
5762
}

Tests/HammerTests/DragTests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Hammer
2+
import XCTest
3+
import Foundation
4+
5+
final class DragTests: XCTestCase {
6+
7+
func test_drag() throws {
8+
let view = TouchTestView()
9+
10+
view.widthAnchor.constraint(equalToConstant: 300).isActive = true
11+
view.heightAnchor.constraint(equalToConstant: 300).isActive = true
12+
13+
let eventGenerator = try EventGenerator(view: view)
14+
try eventGenerator.waitUntilHittable(timeout: 1)
15+
16+
try eventGenerator.fingerDown(at: view.frame.center.offset(x: -50, y: 0))
17+
try eventGenerator.fingerMove(to: view.frame.center.offset(x: 50, y: 0), duration: 0.3)
18+
try eventGenerator.fingerUp()
19+
20+
let endPoint = view.touches.first!.location(in: view)
21+
XCTAssertEqual(endPoint, CGPoint(x: 200, y: 150), accuracy: 0.001)
22+
}
23+
24+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import UIKit
2+
3+
final class TouchTestView: UIView {
4+
5+
var touches: Set<UITouch> = .init()
6+
7+
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
8+
super.touchesBegan(touches, with: event)
9+
10+
touches.forEach { self.touches.insert($0) }
11+
}
12+
13+
}

0 commit comments

Comments
 (0)