Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

[ios] Add threshold for triggering the rotate gesture recognizer - #14929

Merged
jmkiley merged 42 commits into
masterfrom
jmkiley-rotate-pinch
Aug 21, 2019
Merged

jmkiley merged 42 commits into
masterfrom
jmkiley-rotate-pinch

Conversation

@jmkiley

@jmkiley jmkiley commented Jun 15, 2019

Copy link
Copy Markdown
Contributor

Addresses #6562

I'm currently using a higher minimum rotation (+/- 50 degrees) for debugging purposes.

Current issues:

  • The logic to prevent rotation happens when the pinch gesture is not happening.
  • After the rotation has exceeded X number of degrees, it jumps to the new rotation, rather than starting to rotate at that point.

cc @chloekraw

@jmkiley jmkiley added iOS Mapbox Maps SDK for iOS ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold labels Jun 15, 2019
@jmkiley jmkiley self-assigned this Jun 15, 2019
@jmkiley
jmkiley force-pushed the jmkiley-rotate-pinch branch from 4c07cc2 to 62edef6 Compare July 12, 2019 20:02
@chloekraw chloekraw added this to the release-q milestone Jul 15, 2019
@chloekraw chloekraw added the needs changelog Indicates PR needs a changelog entry prior to merging. label Aug 1, 2019
@jmkiley
jmkiley force-pushed the jmkiley-rotate-pinch branch from 62edef6 to 3ae5382 Compare August 2, 2019 23:43
@jmkiley

jmkiley commented Aug 8, 2019 •

Copy link
Copy Markdown
Contributor Author

My current approach:

  • Sets the default threshold for triggering the rotation to 3 degrees. This default value may need to be finetuned a little.
    - Adds a property to MGLMapView which allows users to set custom thresholds.

The threshold currently applies to all rotation gestures, not just when the rotation gesture recognizer is triggered while pinching.

cc @julianrex @friedbunny

@jmkiley

jmkiley commented Aug 9, 2019

Copy link
Copy Markdown
Contributor Author

I've changed my approach to match the approach that Android takes, which is to provide a BOOL property (increasesRotationThresholdWhenZooming) that can increase the rotation threshold. I set the rotation threshold to 45 degrees if that BOOL is set to true.

I am seeing an issue where the map can snap back while rotating without pinching, and would love to pair with someone to work out what is happening.

@jmkiley

jmkiley commented Aug 12, 2019

Copy link
Copy Markdown
Contributor Author

Thanks @fabian-guerra for helping me to troubleshoot. Using the velocity property rather than scale in order to detect zooming seems to have resolved the issue. The default rotation threshold value is now 7.5 degrees, but additional testing may be required in order to find the right value.

I have started writing tests for these changes.

Comment thread platform/ios/src/MGLMapView.mm Resolved
Comment thread platform/ios/src/MGLMapView.h Resolved
Comment thread platform/ios/src/MGLMapView.mm Outdated
[self cancelTransitions];

if (MGLDegreesFromRadians(self.currentRotation) < self.rotationThreshold && self.isZooming) {
[self notifyGestureDidBegin];

@friedbunny friedbunny Aug 13, 2019 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this when the gesture begins? This looks like where the gesture is being explicitly kept from beginning.

@jmkiley jmkiley Aug 13, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The exception that I see from the return; is happening when _changeDelimiterSuppressionDepth is < 0. Just calling _changeDelimiterSuppressionDepth++; seems to make the first rotation jump to a new rotation. I still see that jumpiness occasionally when calling notifyGestureDidBegin.

Right now, this code is still being called when the rotation gesture ends/fails, even if the map doesn't rotate:

[self notifyGestureDidEndWithDrift:YES];
__weak MGLMapView *weakSelf = self;
[self animateWithDelay:decelerationRate animations:^
{
[weakSelf unrotateIfNeededForGesture];
}];

Removing return may work better. The camera animations, tracking, etc. are going to be cancelled by the pinch gesture recognizer that is also being triggered.

@jmkiley

jmkiley commented Aug 13, 2019

Copy link
Copy Markdown
Contributor Author

Current approach is to adjust the threshold internally. The rotation threshold is currently 3 degrees, which should make the rotation slightly less easy to trigger.

@friedbunny

Copy link
Copy Markdown
Contributor

@jmkiley @chloekraw Since these are significant changes and we will only have a maximum of one week of testing before the stable release, I’d like to propose that we don’t enable this by default and instead keep it behind a feature flag — that would make it available for further testing, but not expose the entire install base to a potentially buggy change.

Comment thread platform/ios/src/MGLMapView.mm Resolved
@jmkiley

jmkiley commented Aug 20, 2019

Copy link
Copy Markdown
Contributor Author

I think this is ready for re-review. I removed the changelog entry since this is a feature flag, but let me know if I should add it back in.

Comment thread platform/ios/src/MGLMapView.mm Resolved
Comment thread platform/ios/src/MGLMapView.mm Resolved
{
if ( ! self.isRotateEnabled) return;

if ([[NSUserDefaults standardUserDefaults] objectForKey:MGLRotationThresholdWhileZoomingKey]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This check might be better done where the UIRotationGestureRecognizer is setup in the first place - i.e. change the selector.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We might want to keep it in here in case the rotation threshold changes after the commonInit.

Comment thread platform/ios/src/MGLMapView.mm Resolved
@friedbunny friedbunny added beta blocker Blocks the next beta release UX and removed needs changelog Indicates PR needs a changelog entry prior to merging. labels Aug 21, 2019

@friedbunny friedbunny left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we’re at a good place! Fairly soon after the release branch cuts, I think we’ll want to replace the old handleRotateGesture: implementation and switch over to the new one for more testing in the run-up to the next release.

@julianrex julianrex left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this! Let's ticket up the tail work.

@jmkiley
jmkiley merged commit 6f78560 into master Aug 21, 2019
@jmkiley
jmkiley deleted the jmkiley-rotate-pinch branch August 21, 2019 05:12
@chloekraw

Copy link
Copy Markdown
Contributor

🎊

Congrats on landing this, @jmkiley!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

beta blocker Blocks the next beta release iOS Mapbox Maps SDK for iOS UX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants