-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove hapticFeedbackEnabled (#663) * remove hapticFeedbackEnabled` * clean up changelog * Make gestureOptions.decelarationRate the source of truth (#662) * making gesture options decelaration rate the source of truth * clean up changelog * fix indentation * Internalize UIGestureRecognizerDelegate (#669) * seperated gesture recognizer delegate into a new class and fixed downstream breaks * adding changelog * swift lint and code clean up * adding a comment * pr comments * Refactor gestures (#677) #### Breaking Changes - Pan deceleration has been temporarily removed - `TapGestureHandler.init` was previously public by mistake and is now internal - The behavior of `GestureManager.options` has been updated to better reflect the `isEnabled` state of the associated gesture recognizers - The gesture recognizer properties of `GestureManager` are no longer `Optional` - `GestureType` has been redesigned so that its cases have a 1-1 relationship with the built-in gestures #### Public API Additions - `CameraState`'s fields are now `var`s instead of `let`s for testing purposes, and a public, memberwise initializer has been added. - `PanScrollingMode` now conforms to `CaseIterable` - `GestureType` now conforms to `CaseIterable` #### Bug fixes - GestureManager no longer sets itself as the delegate of all gestures in MapView when its options change #### Internal Refactoring - Generalizes `CameraAnimatorMapboxMap` by renaming it to `MapboxMapProtocol` so that it can be used throughout the SDK. SDK seems small enough that per-component dependency inversion feels unnecessary and might negatively impact binary size. - Removes old `GestureHandlerDelegate` by injecting `MapboxMap` and `CameraAnimationsManager` into each gesture handler to allow each handler to manipulate the camera directly. - Removes unnecessary `GestureContextProvider` - Refactors handlers and `GestureManager` for dependency injection and more thorough tests - Tidies up handlers and `GestureManager` and associated tests for greater consistency * Pan Deceleration (#692) * update changelog * fix changelog * Gesture Options Cleanup (#696) * wip * Change double tap to zoom out to "double touch" * Fix warning * Lint * Update changelog * [run device tests] * Use explicit self Co-authored-by: Andrew Hershberger <andrew.hershberger@mapbox.com> Co-authored-by: Nishant Karajgikar <nishant.karajgikar@mapbox.com>
- Loading branch information
1 parent
ddcf9f2
commit 00a6629
Showing
64 changed files
with
2,389 additions
and
1,947 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
Sources/MapboxMaps/Foundation/Camera/CameraAnimatorMapboxMap.swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
Sources/MapboxMaps/Foundation/Camera/GestureDecelerationCameraAnimator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import UIKit | ||
|
||
internal final class GestureDecelerationCameraAnimator: NSObject, CameraAnimatorInterface { | ||
|
||
private var location: CGPoint | ||
private var velocity: CGPoint | ||
private let decelerationFactor: CGFloat | ||
private let locationChangeHandler: (CGPoint) -> Void | ||
private var previousDate: Date? | ||
private let dateProvider: DateProvider | ||
internal var completion: (() -> Void)? | ||
|
||
internal init(location: CGPoint, | ||
velocity: CGPoint, | ||
decelerationFactor: CGFloat, | ||
locationChangeHandler: @escaping (CGPoint) -> Void, | ||
dateProvider: DateProvider) { | ||
self.location = location | ||
self.velocity = velocity | ||
self.decelerationFactor = decelerationFactor | ||
self.locationChangeHandler = locationChangeHandler | ||
self.dateProvider = dateProvider | ||
} | ||
|
||
internal private(set) var state: UIViewAnimatingState = .inactive | ||
|
||
internal func cancel() { | ||
stopAnimation() | ||
} | ||
|
||
internal func startAnimation() { | ||
previousDate = dateProvider.now | ||
state = .active | ||
} | ||
|
||
internal func stopAnimation() { | ||
state = .inactive | ||
completion?() | ||
completion = nil | ||
} | ||
|
||
internal func update() { | ||
guard state == .active, let previousDate = previousDate else { | ||
return | ||
} | ||
|
||
let currentDate = dateProvider.now | ||
self.previousDate = currentDate | ||
|
||
let elapsedTime = CGFloat(currentDate.timeIntervalSince(previousDate)) | ||
|
||
// calculate new location showing how far we have traveled | ||
location.x += velocity.x * elapsedTime | ||
location.y += velocity.y * elapsedTime | ||
|
||
locationChangeHandler(location) | ||
|
||
// deceleration factor should be applied to the velocity once per millisecond | ||
velocity.x *= pow(decelerationFactor, (elapsedTime * 1000)) | ||
velocity.y *= pow(decelerationFactor, (elapsedTime * 1000)) | ||
|
||
guard abs(velocity.x) >= 1 || abs(velocity.y) >= 1 else { | ||
stopAnimation() | ||
return | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.