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

Zoom focal point #1122

Merged
merged 18 commits into from
Feb 23, 2022
Merged

Zoom focal point #1122

merged 18 commits into from
Feb 23, 2022

Conversation

evil159
Copy link
Contributor

@evil159 evil159 commented Feb 15, 2022

This PR introduces the ability to override the focal point for zoom gestures. If the focal point is set e.g. to the center of the map, then zoom will anchor on that point, disregarding the actual touch location of any zoom gesture.

List of gestures supporting focal point override:

  • double-tap to zoom in
  • double touch to zoom out
  • quick zoom
  • pinch

Fixes #879

Pull request checklist:

  • Write tests for all new functionality. If tests were not written, please explain why.
  • Add documentation comments for any added or updated public APIs.
  • Describe the changes in this PR, especially public API changes.
  • Add a changelog entry to to bottom of the relevant section (typically the ## main heading near the top).
  • Review and agree to the Contributor License Agreement (CLA).

@evil159 evil159 requested a review from OdNairy February 15, 2022 15:35
@macdrevx
Copy link
Contributor

I'm working on doing away with the two pinch gesture implementations. It probably won't land until later this week or early next week, but I wanted to give you a heads-up about it since pan impl 2 is going away.

Copy link
Contributor

@macdrevx macdrevx left a comment

Choose a reason for hiding this comment

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

Holding further feedback until we discuss these initial comments.

/// By default, gestures rotate and zoom around the center of the gesture. Set this property to rotate and zoom around a fixed point instead.
///
/// In order to force the map to only revolve around the specified focal point, disable
/// ``GestureOptions/pinchPanEnabled`` and ``GestureOptions/panEnabled``.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's necessary to disable GestureOptions.panEnabled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leaving regular pan enabled will enable the visible portion of the map to be moved relative to the specified focal point. So a completely different location might end up under the focal point instead of the location shown initially.

Copy link
Contributor

Choose a reason for hiding this comment

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

@pengdev any thoughts on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think if we're going to mention panEnabled it should be in the context of keeping a map coordinate fixed at specific focal point. That's a slightly different use case than forcing rotation and zoom to happen at a specified point.

Copy link
Member

Choose a reason for hiding this comment

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

Could you help me understanding the issue here?
On Android I think we have a focalPoint variable in the CameraAnimations plugin, where gestures in some cases cache the original focalPoint during certain gestures and restore the original focalPoint when the gesture is finished.

cc @kiryldz for more context on how we handle focal point on camera animations and gestures plugin.

Copy link
Contributor

Choose a reason for hiding this comment

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

After further debate, we've decided to allow gesture options to have pinchPanEnabled == true and focalPoint != nil simultaneously. In this case, focalPoint will be ignored for the pinch gesture, but it will still apply to the zoom gestures. When pinch gesture starts, we'll log a warning to inform developers that they may want to set pinchPanEnabled = false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made it so 👍

Comment on lines 495 to 503
let secondFocalPoint = CGPoint.random()
doubleTapToZoomInGestureHandler.focalPoint = secondFocalPoint

XCTAssertEqual(gestureManager.options.focalPoint, doubleTapToZoomInGestureHandler.focalPoint)

doubleTapToZoomInGestureHandler.focalPoint = nil

XCTAssertNil(gestureManager.options.focalPoint)

Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend omitting this aspect of the test. Unlike setting isEnabled on a publicly-exposed gesture recognizer, we don't expose a way for developers to modify focalPoint on doubleTapToZoomInGestureHandler — it's just an implementation detail.

The other part of the test is the important part.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point, removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems it's not fully removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now it should be 🤞

CHANGELOG.md Outdated
Comment on lines 16 to 17
* Zoom focal point ([#1122](https://github.com/mapbox/mapbox-maps-ios/pull/1122))
* Add focalPoint property to zoom and rotate gestures ([#1122](https://github.com/mapbox/mapbox-maps-ios/pull/1122))
Copy link
Member

Choose a reason for hiding this comment

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

nit: duplicated change log entries for the same PR, probably we want to remove the first one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well spotted, rebase artefacts, removed it.

@@ -1,3 +1,5 @@
import CoreGraphics
Copy link
Member

Choose a reason for hiding this comment

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

nit: I'm not familiar with swift, but is it needed as there's no other change in this class besides this import.

Copy link
Contributor

Choose a reason for hiding this comment

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

Xcode has started auto-importing frameworks which is leading to a lot of things like this happening. Probably there were other changes to this file in a previous iteration of this PR which led to this import which was then not reverted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@macdrevx exactly! I'm willing to keep it, Xcode has a point - we do use CoreGrapics types here.

@@ -1,9 +1,11 @@
import UIKit
@_implementationOnly import MapboxCommon_Private
Copy link
Contributor

Choose a reason for hiding this comment

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

This import can be removed now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one stays, but the one from GestureOptions goes :)

evil159 and others added 2 commits February 23, 2022 02:26
@evil159 evil159 enabled auto-merge (squash) February 23, 2022 00:40
@evil159 evil159 merged commit 1c862c7 into main Feb 23, 2022
@evil159 evil159 deleted the zoom-focal-point branch February 23, 2022 00:49
OdNairy pushed a commit that referenced this pull request Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to specify anchor for Zoom gestures
4 participants