Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gesture Options Cleanup #696

Merged
merged 5 commits into from
Sep 22, 2021

Conversation

macdrevx
Copy link
Contributor

@macdrevx macdrevx commented Sep 22, 2021

Pull request checklist:

  • Briefly describe the changes in this PR.
  • Write tests for all new functionality. If tests were not written, please explain why.
  • Document any changes to public APIs.
  • Apply changelog label ('breaking change', 'bug 🪲', 'build', 'docs', 'feature 🍏', 'performance ⚡', 'testing 💯') or use the label 'skip changelog'
  • Update the changelog

Summary of changes

  • Updates "enabled" gesture options to have a 1-1 mapping with available gestures.
  • Changes "double tap to zoom out" gesture to "double touch to zoom out" gesture for consistency with Android SDK, and splits the corresponding handler implementations into 2 classes.
  • Merges the rotate gesture into the pinch gesture, which allows correct anchoring of the rotation around the midpoint of the gesture.
  • Adds logic to ensure that the initial state of the gesture handlers and recognizers is consistent with the default values specified on the GestureOptions struct.

Breaking changes

  • GestureManager.rotationGestureRecognizer has been removed. Rotation is now handled by .pinchGestureRecognizer in addition to its preexisting handling of panning and zooming.
  • GestureManager.doubleTapToZoomOutGestureRecognizer has been replaced with .doubleTouchToZoomOutGestureRecognizer
  • PanScrollingMode has been renamed to PanMode
  • GestureOptions.zoomEnabled has been replaced by .doubleTapToZoomInEnabled, .doubleTouchToZoomOutEnabled, and .quickZoomEnabled
  • GestureOptions.rotateEnabled has been removed
  • GestureOptions.scrollEnabled has been renamed to .panEnabled
  • GestureOptions.scrollingMode has been renamed to .panMode
  • GestureOptions.decelerationRate has been renamed to .panDecelerationFactor
  • GestureType.doubleTapToZoomOut has been replaced with .doubleTouchToZoomOut
  • GestureType.rotate has been removed
  • GestureType cases have been reordered for consistency with GestureOptions and GestureManager

Bug Fixes

  • Fixes an issue where tapping the compass could fail to set the bearing to 0 if there was already an animation running. Tapping the compass now cancels any existing animations.
  • Fixes issues with the pinch gesture when removing and re-adding one of the two required touches
  • Fixes an issue where a pan gesture would fail if it interrupted the deceleration from a previous pan gesture.

@macdrevx macdrevx added bug 🪲 Something is broken! skip changelog Add this label if this item does not need to be included in the changelog breaking change ⚠️ If your pull request introduces a breaking change and updates are required when version is published labels Sep 22, 2021
@macdrevx macdrevx changed the base branch from main to feature/gestures_cleanup September 22, 2021 03:25
@macdrevx macdrevx added this to the ga milestone Sep 22, 2021
/// A constant factor that determines how quickly pan deceleration animations happen.
/// Multiplied with the velocity vector once per millisecond during deceleration animations.
/// Defaults to `UIScrollView.DecelerationRate.normal.rawValue`
public var panDecelerationFactor: CGFloat = UIScrollView.DecelerationRate.normal.rawValue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

everywhere else in the code, this has been called decelerationFactor. Why is it that the options have a prepended pan in front of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to indicate that this setting only applies to pan. In the other locations, the meaning is clear from the context. Later, we might add other separate deceleration factor options for other gestures, so the prefix sets us up to be able to do that in an additive way.

case doubleTapToZoomIn

/// The double touch to zoom out gesture
case doubleTouchToZoomOut
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Let's order these alphabetically

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we debate this in a separate ticket?

Comment on lines -66 to -68
self.initialTouchLocation = nil
self.initialCameraState = nil
self.lastChangedDate = nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make this completion optional? Seems like it should be nullable instead of sending an empty closure here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's address this in a future pr.

@nishant-karajgikar nishant-karajgikar merged commit befe6e1 into feature/gestures_cleanup Sep 22, 2021
@nishant-karajgikar nishant-karajgikar deleted the ah/gesture-options branch September 22, 2021 18:09
nishant-karajgikar added a commit that referenced this pull request Sep 22, 2021
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change ⚠️ If your pull request introduces a breaking change and updates are required when version is published bug 🪲 Something is broken! skip changelog Add this label if this item does not need to be included in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants