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

Commit

Permalink
Introduce limited axis scrolling (#108)
Browse files Browse the repository at this point in the history
MGLUserScrollingMode -> MGLPanScrollingMode

Add changelog entry

Remove NSLog
  • Loading branch information
captainbarbosa committed Jan 10, 2020
1 parent 58aa001 commit 309e226
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
5 changes: 5 additions & 0 deletions platform/ios/CHANGELOG.md
Expand Up @@ -2,6 +2,11 @@

Mapbox welcomes participation and contributions from everyone. Please read [CONTRIBUTING.md](../../CONTRIBUTING.md) to get started.

## master

### Other changes
* Added new property `MGLMapView.panScrollingMode`, which allows you to limit the horizontal or vertical direction a user may pan on the map view. ([#108](https://github.com/mapbox/mapbox-gl-native-ios/pull/108))

## 5.6.0 - December 19, 2019
This release includes a known issue where the binary size has increased. [#63](https://github.com/mapbox/mapbox-gl-native-ios/issues/63)

Expand Down
23 changes: 23 additions & 0 deletions platform/ios/src/MGLMapView.h
Expand Up @@ -105,6 +105,15 @@ typedef NS_ENUM(NSUInteger, MGLUserTrackingMode) {
MGLUserTrackingModeFollowWithCourse,
};

typedef NS_ENUM(NSUInteger, MGLPanScrollingMode) {
/** The map allows the user to only scroll horizontally. */
MGLPanScrollingModeHorizontal = 0,
/** The map allows the user to only scroll vertically. */
MGLPanScrollingModeVertical,
/** The map allows the user to scroll both horizontally and vertically. */
MGLPanScrollingModeDefault
};

/** Options for `MGLMapView.preferredFramesPerSecond`. */
typedef NSInteger MGLMapViewPreferredFramesPerSecond NS_TYPED_EXTENSIBLE_ENUM;

Expand Down Expand Up @@ -689,6 +698,20 @@ MGL_EXPORT
*/
@property(nonatomic, getter=isScrollEnabled) BOOL scrollEnabled;

/**
The scrolling mode the user is allowed to use to interact with the map.
`MGLPanScrollingModeHorizontal` only allows the user to scroll horizontally on the map,
restricting a user's ability to scroll vertically.
`MGLPanScrollingModeVertical` only allows the user to scroll vertically on the map,
restricting a user's ability to scroll horizontally.
`MGLPanScrollingModeDefault` allows the user to scroll both horizontally and vertically
on the map.
By default, this property is set to `MGLPanScrollingModeDefault`.
*/
@property (nonatomic, assign) MGLPanScrollingMode panScrollingMode;

/**
A Boolean value that determines whether the user may rotate the map,
changing the direction.
Expand Down
24 changes: 22 additions & 2 deletions platform/ios/src/MGLMapView.mm
Expand Up @@ -586,6 +586,7 @@ - (void)commonInit
_pan.maximumNumberOfTouches = 1;
[self addGestureRecognizer:_pan];
_scrollEnabled = YES;
_panScrollingMode = MGLPanScrollingModeDefault;

_pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];
_pinch.delegate = self;
Expand Down Expand Up @@ -1730,7 +1731,17 @@ - (void)handlePanGesture:(UIPanGestureRecognizer *)pan

if ([self _shouldChangeFromCamera:oldCamera toCamera:toCamera])
{
self.mbglMap.moveBy({ delta.x, delta.y });
switch(self.panScrollingMode){
case MGLPanScrollingModeVertical:
self.mbglMap.moveBy({ 0, delta.y });
break;
case MGLPanScrollingModeHorizontal:
self.mbglMap.moveBy({ delta.x, 0 });
break;
default:
self.mbglMap.moveBy({ delta.x, delta.y });
}

[pan setTranslation:CGPointZero inView:pan.view];
}

Expand All @@ -1753,7 +1764,16 @@ - (void)handlePanGesture:(UIPanGestureRecognizer *)pan

if ([self _shouldChangeFromCamera:oldCamera toCamera:toCamera])
{
self.mbglMap.moveBy({ offset.x, offset.y }, MGLDurationFromTimeInterval(self.decelerationRate));
switch(self.panScrollingMode){
case MGLPanScrollingModeVertical:
self.mbglMap.moveBy({ 0, offset.y }, MGLDurationFromTimeInterval(self.decelerationRate));
break;
case MGLPanScrollingModeHorizontal:
self.mbglMap.moveBy({ offset.x, 0 }, MGLDurationFromTimeInterval(self.decelerationRate));
break;
default:
self.mbglMap.moveBy({ offset.x, offset.y }, MGLDurationFromTimeInterval(self.decelerationRate));
}
}
}

Expand Down

0 comments on commit 309e226

Please sign in to comment.