Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Unified Diff: ios/chrome/browser/ui/side_swipe/side_swipe_navigation_view.mm

Issue 2709233003: Add haptic feedback for swipe-to-go-back. (Closed)
Patch Set: File is ARC. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/side_swipe/side_swipe_navigation_view.mm
diff --git a/ios/chrome/browser/ui/side_swipe/side_swipe_navigation_view.mm b/ios/chrome/browser/ui/side_swipe/side_swipe_navigation_view.mm
index 24dbefc133527e548c280c500346c74102ad9402..ca4fa6d282be5e5ccc09230ff1ef18b843b1dabe 100644
--- a/ios/chrome/browser/ui/side_swipe/side_swipe_navigation_view.mm
+++ b/ios/chrome/browser/ui/side_swipe/side_swipe_navigation_view.mm
@@ -66,6 +66,9 @@ const CGFloat kSelectionAnimationDuration = 0.5;
@interface SideSwipeNavigationView () {
@private
+ // Has the current swipe gone past the point where the action would trigger?
+ // Will be reset to NO if it recedes before that point (ie, not a latch).
+ BOOL thresholdTriggered_;
// The back or forward sprite image.
base::scoped_nsobject<UIImageView> arrowView_;
@@ -210,11 +213,18 @@ const CGFloat kSelectionAnimationDuration = 0.5;
selectionCircleLayer_.opacity = 0;
[arrowView_ setAlpha:MapValueToRange({0, 64}, {0, 1}, distance)];
[arrowView_ setTintColor:[UIColor whiteColor]];
+ thresholdTriggered_ = NO;
} else {
selectionCircleLayer_.transform = CATransform3DMakeScale(1, 1, 1);
selectionCircleLayer_.opacity = 0.75;
[arrowView_ setAlpha:1];
[arrowView_ setTintColor:self.backgroundColor];
+ // Trigger a small haptic blip when exceeding the threshold and mark
+ // such that only one blip gets triggered.
+ if (!thresholdTriggered_) {
+ TriggerHapticFeedbackForSelectionChange();
+ thresholdTriggered_ = YES;
+ }
}
[UIView commitAnimations];
}
@@ -329,6 +339,8 @@ const CGFloat kSelectionAnimationDuration = 0.5;
// and that the distance including expected velocity is over |threshold|.
if (distance > kArrowThreshold && finalDistance > threshold &&
canNavigate_ && gesture.state == UIGestureRecognizerStateEnded) {
+ TriggerHapticFeedbackForAction();
+
// Speed up the animation for higher velocity swipes.
CGFloat animationTime = MapValueToRange(
{threshold, width},
@@ -358,6 +370,7 @@ const CGFloat kSelectionAnimationDuration = 0.5;
base::UserMetricsAction("MobileEdgeSwipeNavigationBackCancelled"));
}
}
+ thresholdTriggered_ = NO;
}
}
« no previous file with comments | « ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.mm ('k') | ios/chrome/browser/ui/uikit_ui_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698