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

Make tap gesture recognizer fail if it doesn’t do anything #7246

Merged
merged 7 commits into from
Dec 1, 2016

Conversation

JesseCrocker
Copy link
Contributor

I couldn't tell from the discussion on #2278 and #7194 if implementation of this was already in progress or not, but i needed this functionality to be able to continue with a progress. If this is already is progress, please ignore this PR.

@mention-bot
Copy link

@JesseCrocker, thanks for your PR! By analyzing this pull request, we identified @1ec5, @friedbunny and @incanus to be potential reviewers.

Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

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

This is a great solution to #2278. I have some questions about edge cases below that you probably understand better than I do.

Is any of this relevant to the macOS implementation of MGLMapView, which also has a built-in single tap gesture recognizer?

Would you do the honors and update the changelogs?

@param singleTap An in progress tap gesture recognizer.
@param persist True to remember the cycleable set of annotations. @see annotationTagAtPoint:persistingResults
*/
- (id <MGLAnnotation> _Nullable)annotationForGestureRecognizer:(UITapGestureRecognizer*)singleTap persistingResults:(BOOL)persist
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: use the nullable keyword.

else if (gestureRecognizer == _singleTapGestureRecognizer)
{
//Gesture will be recognized if it could deselect an annotation
if(!self.selectedAnnotation)
Copy link
Contributor

Choose a reason for hiding this comment

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

What if an annotation is selected and tapping would ordinarily deselect it? Wouldn't this prevent the single tap gesture recognizer from firing to deselect the annotation?

Copy link
Contributor Author

@JesseCrocker JesseCrocker Dec 1, 2016

Choose a reason for hiding this comment

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

If this is false, it returns YES from the last line of the method, so the recognizer runs


Your application can use this to modify the behavior of your own gesture recognizers.
*/
@property (nonatomic, readonly) UITapGestureRecognizer *singleTapGestureRecognizer;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it enough for the application's gesture recognizers to avoid conflicts with this one gesture recognizer, or is it also necessary to avoid conflicts with, say, the double-tap gesture recognizer? Would it make sense for the application's gesture recognizer to require all the map view gesture recognizers (via the gestureRecognizers property) to fail? Or would those other gesture recognizers need to defer to the application's single tap gesture recognizer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my case im not actually using this property, and instead im requiring all other gesture recognizers to fail. So maybe this property is not needed. Do you think i should remove it?

    for(UIGestureRecognizer *r in self.glMapView.gestureRecognizers) {
      [self.tapGestureRecognizer requireGestureRecognizerToFail:r];
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, let’s leave out the property for now. If someone really needs it, they can filter the array for UITapGestureRecognizers as a workaround. That leaves MGLMapView free to install additional gesture recognizers in the future for other purposes.

@JesseCrocker JesseCrocker changed the title [ios] Make tap gesture recognizer fail if it doesn’t do anything. [iOS, macoOS] Make tap gesture recognizer fail if it doesn’t do anything. Dec 1, 2016
@1ec5 1ec5 added annotations Annotations on iOS and macOS or markers on Android feature iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS labels Dec 1, 2016
@1ec5 1ec5 modified the milestone: ios-3.4.1 Dec 1, 2016
@@ -57,6 +57,7 @@
* Fixed an issue where the map view’s center would always be calculated as if the view occupied the entire window. ([#6102](https://github.com/mapbox/mapbox-gl-native/pull/6102))
* Notification names and user info keys are now string enumeration values for ease of use in Swift. ([#6794](https://github.com/mapbox/mapbox-gl-native/pull/6794))
* Fixed a typo in the documentation for the MGLCompassDirectionFormatter class. ([#5879](https://github.com/mapbox/mapbox-gl-native/pull/5879))
* The NSClickGestureRecognizer on MGLMapView that is used for selecting annotations now fails if a tap does not select an annotation. ([#7246](https://github.com/mapbox/mapbox-gl-native/pull/7246))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: it’s a click, not a tap. 🖱


Your application can use this to modify the behavior of your own gesture recognizers.
*/
@property (nonatomic, readonly) UITapGestureRecognizer *singleTapGestureRecognizer;
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, let’s leave out the property for now. If someone really needs it, they can filter the array for UITapGestureRecognizers as a workaround. That leaves MGLMapView free to install additional gesture recognizers in the future for other purposes.

@1ec5
Copy link
Contributor

1ec5 commented Dec 1, 2016

Thanks again for this PR – it’s looking solid. By the way, it’d be nice to get this feature into the v3.4.0 or v3.4.1 release. We’re developing the v3.4.x series on the release-ios-v3.4.0 branch. Would you mind retargeting this PR and rebasing this branch on release-ios-v3.4.0? (There’s an option to retarget the PR when editing the PR’s title.) We’ll periodically merge this branch to master as prereleases and releases go out.

@1ec5 1ec5 changed the title [iOS, macoOS] Make tap gesture recognizer fail if it doesn’t do anything. Make tap gesture recognizer fail if it doesn’t do anything Dec 1, 2016
@JesseCrocker JesseCrocker changed the base branch from master to release-ios-v3.4.0 December 1, 2016 19:08
@JesseCrocker
Copy link
Contributor Author

Rebased, and re-targeted

@1ec5 1ec5 added this to the ios-v3.4.0 milestone Dec 1, 2016
@1ec5 1ec5 merged commit 5dd71d3 into mapbox:release-ios-v3.4.0 Dec 1, 2016
@1ec5 1ec5 mentioned this pull request Jan 8, 2017
@JesseCrocker JesseCrocker deleted the tap-gesture-fail branch March 3, 2017 13:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
annotations Annotations on iOS and macOS or markers on Android feature iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants