-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[ios] Disable/enable related gesture recognizer when disabling/enabling user interactivity. #8304
[ios] Disable/enable related gesture recognizer when disabling/enabling user interactivity. #8304
Conversation
@davidchiles, thanks for your PR! By analyzing this pull request, we identified @incanus, @1ec5 and @boundsj to be potential reviewers. |
Thanks! I think this is a good implementation of the suggestion in #7217 (comment) to fully disable gesture recognizers instead of short circuiting their handlers. When they are disabled, then containing view recognizers (like a UIScrollView) work as expected (as illustrated by the new demo in the iosapp in this PR). The full list is of gesture recognizers affected with this proposal are:
All of the handlers noted in this list have guards like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great addition and fixes! Just some critiques and typos I've called out, many of which are minor nitpicks but contribute to overall code quality.
platform/ios/app/MBXViewController.m
Outdated
MBXSettingsMiscellaneousPrintLogFile, | ||
MBXSettingsMiscellaneousDeleteLogFile, | ||
MBXSettingsMiscellaneousDeleteLogFile | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nix this space.
platform/ios/app/MBXViewController.m
Outdated
MBXSettingsMiscellaneousPrintLogFile, | ||
MBXSettingsMiscellaneousDeleteLogFile, | ||
MBXSettingsMiscellaneousDeleteLogFile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our internal style is to retain commas in these situations to make it easier to rearrange and add new entries.
platform/ios/app/MBXViewController.m
Outdated
@@ -350,6 +353,7 @@ - (void)dismissSettings:(__unused id)sender | |||
@"Start World Tour", | |||
[NSString stringWithFormat:@"%@ Custom User Dot", (_customUserLocationAnnnotationEnabled ? @"Disable" : @"Enable")], | |||
[NSString stringWithFormat:@"%@ Zoom Level", (_showZoomLevelEnabled ? @"Hide" :@"Show")], | |||
@"Embeded Map View" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another trailing comma to add.
platform/ios/app/MBXViewController.m
Outdated
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; | ||
MBXEmbededMapViewController *embeddedMapViewController = (MBXEmbededMapViewController *)[storyboard instantiateViewControllerWithIdentifier:@"MBXEmbededMapViewController"]; | ||
[self.navigationController pushViewController:embeddedMapViewController animated:YES]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove blank line.
platform/ios/src/MGLMapView.mm
Outdated
@property (nonatomic) UIPanGestureRecognizer *pan; | ||
@property (nonatomic) UIPinchGestureRecognizer *pinch; | ||
@property (nonatomic) UIRotationGestureRecognizer *rotate; | ||
@property (nonatomic) UITapGestureRecognizer *doubleTap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep the taps all together?
self.mapView.transform = CGAffineTransformRotate(rotationGesture.view.transform, rotationGesture.rotation); | ||
} | ||
|
||
- (void)switchContorl:(MBXEmbeddedControl) control { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo.
[self.view addSubview:stackView]; | ||
} | ||
|
||
- (void)didSwitch:(UISwitch *)sw { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We always try to write out variable names.
|
||
//Create list of all the possible control titles | ||
NSMutableArray <UIView*>*items = [[NSMutableArray alloc] init]; | ||
for(NSInteger index =0; index < 4; index++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistent spacing.
}; | ||
|
||
|
||
@interface MBXEmbededMapViewController () <UIScrollViewDelegate> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class name is misspelled: Embeded
.
// | ||
// Created by David Chiles on 3/7/17. | ||
// Copyright © 2017 Mapbox. All rights reserved. | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comment header & personal identification.
switchControl.tag = index; | ||
[switchControl addTarget:self action:@selector(didSwitch:) forControlEvents:UIControlEventValueChanged]; | ||
switchControl.translatesAutoresizingMaskIntoConstraints = NO; | ||
switchControl.on = [self statusForControl:index]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The body of this for
loop seems like a good candidate to break out into a separate method. Considering that there are only four switch controls in all, perhaps it makes sense to set each switch’s title explicitly, track them with separate properties, and hook them up to separate action methods. Someone theoretically adding a “Roll Enabled” switch (!) would have fewer methods to update.
[scrollView addGestureRecognizer:gestureRecognizer]; | ||
|
||
CGRect mapRect = CGRectMake(0, 0, CGRectGetWidth(scrollView.frame) * 2, CGRectGetHeight(scrollView.frame) * 2); | ||
self.mapView = [[MGLMapView alloc] initWithFrame:mapRect]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the view controller itself is already defined in the storyboard, I wonder if it would make the demo clearer if we moved some of this setup to the storyboard as well. Then most of this class’s code would relate to the switches’ behavior instead of the layout code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aye, this is a bit awkward — let’s go one way or the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very fluent in storyboard so I can just remove the view controller from there.
[scrollView addGestureRecognizer:gestureRecognizer]; | ||
|
||
CGRect mapRect = CGRectMake(0, 0, CGRectGetWidth(scrollView.frame) * 2, CGRectGetHeight(scrollView.frame) * 2); | ||
self.mapView = [[MGLMapView alloc] initWithFrame:mapRect]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aye, this is a bit awkward — let’s go one way or the other.
[self.view addSubview:scrollView]; | ||
[scrollView addGestureRecognizer:gestureRecognizer]; | ||
|
||
CGRect mapRect = CGRectMake(0, 0, CGRectGetWidth(scrollView.frame) * 2, CGRectGetHeight(scrollView.frame) * 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not following the purpose of a gigantic map within a scrollview — is this a common use case that we’re demoing? It seems like multiple smaller maps within a regular viewport frame (with only a vertical scroll axis) is a potential use case that would demonstrate these conditionally disabled gestures in a more straightforward way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's true that #7217 demonstrated the need for only vertical (and perhaps horizontal) gesture overrides. However, the solution implemented in this PR technically allows for all possible UIScrollView gestures to function instead of the built in map view gestures. This demo may not be realistic but it is comprehensive and I don't think it would make sense to throw away the pinch and rotate parts in iosapp.
That said, a more realistic example in mapbox/ios-sdk-examples would be helpful, I think.
|
||
@interface MBXEmbeddedMapViewController () <UIScrollViewDelegate> | ||
|
||
@property (nonatomic, strong) MGLMapView *mapView; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, super minor, but strong
is the default so can be left out.
{ | ||
switch (control) { | ||
case MBXEmbeddedControlZoom: | ||
return @"Zoom Enabled"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing break
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A break
isn’t needed after a return
.
platform/ios/app/MBXViewController.m
Outdated
@@ -350,6 +352,7 @@ - (void)dismissSettings:(__unused id)sender | |||
@"Start World Tour", | |||
[NSString stringWithFormat:@"%@ Custom User Dot", (_customUserLocationAnnnotationEnabled ? @"Disable" : @"Enable")], | |||
[NSString stringWithFormat:@"%@ Zoom Level", (_showZoomLevelEnabled ? @"Hide" :@"Show")], | |||
@"Embeded Map View", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo.
_pitchEnabled = pitchEnabled; | ||
self.twoFingerDrag.enabled = pitchEnabled; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love these routines BTW. Great way to see what the setters impact across the view.
Adding this to the 3.6.0 milestone. |
96c81e9
to
2cefd09
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
|
||
self.scrollView.delegate = self; | ||
self.scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.view.bounds), | ||
CGRectGetHeight(self.view.bounds)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.view.bounds.size would have the same effect.
6c7efef
to
4999fc0
Compare
4999fc0
to
96d96d9
Compare
Fixes #7217
Added an example behavior of MGLMapView as a subview of UIScrollView in
iOS app.