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

Commit

Permalink
[ios] Provide haptic feedback when user rotates to due north
Browse files Browse the repository at this point in the history
  • Loading branch information
friedbunny committed Feb 22, 2018
1 parent b79a1cc commit bcb756b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Labels are now transliterated from more languages when VoiceOver is enabled. ([#10881](https://github.com/mapbox/mapbox-gl-native/pull/10881))
* Long-pressing the attribution button causes the SDK’s version number to be displayed in the action sheet that appears. ([#10650](https://github.com/mapbox/mapbox-gl-native/pull/10650))
* Reduced offline download size for styles with symbol layers that render only icons, and no text. ([#11055](https://github.com/mapbox/mapbox-gl-native/pull/11055))
* Added haptic feedback that occurs when the user rotates the map to due north, configurable via `MGLMapView.hapticFeedbackEnabled`. ([#10847](https://github.com/mapbox/mapbox-gl-native/pull/10847))

## 3.7.5 - February 16, 2018

Expand Down
13 changes: 13 additions & 0 deletions platform/ios/src/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,19 @@ MGL_EXPORT IB_DESIGNABLE
*/
@property(nonatomic, getter=isPitchEnabled) BOOL pitchEnabled;

/**
A Boolean value that determines whether the user will receive haptic feedback
for certain interactions with the map.
When this property is set to `YES`, the default, a `UIImpactFeedbackStyleLight`
haptic feedback event be played when the user rotates the map to due north
(0°).
This feature requires a device that supports haptic feedback, running iOS 10 or
newer.
*/
@property(nonatomic, getter=isHapticFeedbackEnabled) BOOL hapticFeedbackEnabled;

/**
A floating-point value that determines the rate of deceleration after the user
lifts their finger.
Expand Down
21 changes: 21 additions & 0 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ @interface MGLMapView () <UIGestureRecognizerDelegate,
@property (nonatomic) CGFloat quickZoomStart;
@property (nonatomic, getter=isDormant) BOOL dormant;
@property (nonatomic, readonly, getter=isRotationAllowed) BOOL rotationAllowed;
@property (nonatomic) BOOL shouldTriggerHapticFeedbackForCompass;
@property (nonatomic) MGLMapViewProxyAccessibilityElement *mapViewProxyAccessibilityElement;
@property (nonatomic) MGLAnnotationContainerView *annotationContainerView;
@property (nonatomic) MGLUserLocation *userLocation;
Expand Down Expand Up @@ -525,6 +526,8 @@ - (void)commonInit
[_twoFingerTap requireGestureRecognizerToFail:_twoFingerDrag];
[self addGestureRecognizer:_twoFingerTap];

_hapticFeedbackEnabled = YES;

_decelerationRate = MGLMapViewDecelerationRateNormal;

_quickZoom = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleQuickZoomGesture:)];
Expand Down Expand Up @@ -1513,6 +1516,8 @@ - (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate
self.userTrackingMode = MGLUserTrackingModeFollow;
}

self.shouldTriggerHapticFeedbackForCompass = NO;

[self notifyGestureDidBegin];
}
else if (rotate.state == UIGestureRecognizerStateChanged)
Expand All @@ -1535,6 +1540,22 @@ - (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate
}

[self cameraIsChanging];

// Trigger a light haptic feedback event when the user rotates to due north.
if (@available(iOS 10.0, *))
{
if (self.isHapticFeedbackEnabled && fabs(newDegrees) <= 1 && self.shouldTriggerHapticFeedbackForCompass)
{
UIImpactFeedbackGenerator *hapticFeedback = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight];
[hapticFeedback impactOccurred];

self.shouldTriggerHapticFeedbackForCompass = NO;
}
else if (fabs(newDegrees) > 1)
{
self.shouldTriggerHapticFeedbackForCompass = YES;
}
}
}
else if (rotate.state == UIGestureRecognizerStateEnded || rotate.state == UIGestureRecognizerStateCancelled)
{
Expand Down

0 comments on commit bcb756b

Please sign in to comment.