Skip to content

Commit

Permalink
Remove unused RotationGestureHandler/scheduleRotationUpdateIfNeeded (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
maios committed Mar 28, 2023
1 parent 315679f commit 2db1066
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import CoreLocation

internal protocol RotateGestureHandlerProtocol: FocusableGestureHandlerProtocol {
var simultaneousRotateAndPinchZoomEnabled: Bool { get set }
func scheduleRotationUpdateIfNeeded()
}

/// `RotateGestureHandler` updates the map camera in response to 2-touch rotate gestures
Expand Down Expand Up @@ -57,31 +56,11 @@ internal protocol RotateGestureHandlerProtocol: FocusableGestureHandlerProtocol
}
}

private var rotationUpdateNeeded = false

/// Appends bearing update to the end of the main queue.
/// The update will be performed only if no other bearing update precedes it.
func scheduleRotationUpdateIfNeeded() {
guard isMapRotating else {
return
}
rotationUpdateNeeded = true
DispatchQueue.main.async {
guard self.rotationUpdateNeeded else {
return
}

self.updateBearing()
}
}

private func updateBearing() {
guard let view = gestureRecognizer.view else {
return
}

rotationUpdateNeeded = false

// flip the sign since the UIKit coordinate system is flipped
// relative to the coordinate system used for bearing.
let rotationInDegrees = -CLLocationDirection(rotateGestureRecognizer.rotation.toDegrees())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,66 +217,6 @@ final class RotateGestureHandlerTests: XCTestCase {

XCTAssertFalse(shouldRecognizeSimultaneously)
}

func testSheduleRotationUpdateIsIgnoredWhenNotRotating() {
let expectation = expectation(description: "Scheduled rotation update ignored")
expectation.isInverted = true
rotateGestureHandler.scheduleRotationUpdateIfNeeded()
DispatchQueue.main.async {
if !self.mapboxMap.setCameraStub.invocations.isEmpty {
expectation.fulfill()
}
}

wait(for: [expectation], timeout: 0.1)
}

func testScheduledRotationUpdateIsPerformed() {
let expectation = expectation(description: "Scheduled rotation update performed")

gestureRecognizer.getStateStub.defaultReturnValue = .began
gestureRecognizer.sendActions()

gestureRecognizer.getStateStub.defaultReturnValue = .changed
gestureRecognizer.getVelocityStub.defaultReturnValue = 1.radiansPerSecond
gestureRecognizer.getRotationStub.defaultReturnValue = 30.toRadians()
gestureRecognizer.sendActions()
mapboxMap.setCameraStub.reset()

rotateGestureHandler.scheduleRotationUpdateIfNeeded()
DispatchQueue.main.async {
if !self.mapboxMap.setCameraStub.invocations.isEmpty {
expectation.fulfill()
}
}
wait(for: [expectation], timeout: 0.1)
}

func testScheduledRotationUpdateIsIgnoredAfterGestureUpdate() {
let expectation = expectation(description: "Scheduled rotation update performed")
expectation.isInverted = true

gestureRecognizer.getStateStub.defaultReturnValue = .began
gestureRecognizer.sendActions()

gestureRecognizer.getStateStub.defaultReturnValue = .changed
gestureRecognizer.getVelocityStub.defaultReturnValue = 1.radiansPerSecond
gestureRecognizer.getRotationStub.defaultReturnValue = 30.toRadians()
gestureRecognizer.sendActions()

mapboxMap.setCameraStub.reset()

rotateGestureHandler.scheduleRotationUpdateIfNeeded()
DispatchQueue.main.async {
// camera should be set only once after gesture recognizer sends its update,
// the scheduled bearing update should be ignored after that
if self.mapboxMap.setCameraStub.invocations.count > 1 {
expectation.fulfill()
}
}
gestureRecognizer.sendActions()
wait(for: [expectation], timeout: 0.1)
}
}

fileprivate extension Double {
Expand Down

0 comments on commit 2db1066

Please sign in to comment.