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

Unified Diff: ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.mm

Issue 2680343002: Add haptic feedback for selection change and action trigger. (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | ios/chrome/browser/ui/overscroll_actions/overscroll_actions_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.mm
diff --git a/ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.mm b/ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.mm
index e74c2c9bacef8b061922c421a4627d4590e7112d..d4a463aac78cee4b80ce267107462a38bdf80ff8 100644
--- a/ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.mm
+++ b/ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.mm
@@ -7,6 +7,7 @@
#import <QuartzCore/QuartzCore.h>
#include <algorithm>
+#include "base/ios/ios_util.h"
#include "base/logging.h"
#include "base/mac/objc_property_releaser.h"
#include "base/mac/scoped_nsobject.h"
@@ -651,6 +652,26 @@ NSString* const kOverscrollActionsDidEnd = @"OverscrollActionsDidStop";
[self clear];
}
+// On iOS10 and above, trigger a haptic vibration for the user selecting an
+// action. This is a no-op for devices that do not support it.
+- (void)triggerHapticFeedbackForAction {
+ if (base::ios::IsRunningOnIOS10OrLater()) {
+ base::scoped_nsobject<UIImpactFeedbackGenerator> generator(
+ [[UIImpactFeedbackGenerator alloc] init]);
+ [generator impactOccurred];
+ }
+}
+
+// On iOS10 and above, trigger a haptic vibration for the change in selection.
+// This is a no-op for devices that do not support it.
+- (void)triggerHapticFeedbackForSelectionChange {
+ if (base::ios::IsRunningOnIOS10OrLater()) {
+ base::scoped_nsobject<UISelectionFeedbackGenerator> generator(
+ [[UISelectionFeedbackGenerator alloc] init]);
+ [generator selectionChanged];
+ }
+}
+
- (BOOL)isOverscrollActionEnabled {
return _overscrollActionLock == 0 && _allowPullingActions &&
!_isOverscrollActionsDisabledForLoading;
@@ -679,6 +700,7 @@ NSString* const kOverscrollActionsDidEnd = @"OverscrollActionsDidStop";
dispatch_async(dispatch_get_main_queue(), ^{
[self recordMetricForTriggeredAction:self.overscrollActionView
.selectedAction];
+ [self triggerHapticFeedbackForAction];
[self.delegate overscrollActionsController:self
didTriggerAction:self.overscrollActionView
.selectedAction];
@@ -894,9 +916,16 @@ NSString* const kOverscrollActionsDidEnd = @"OverscrollActionsDidStop";
[self scrollView].panGestureRecognizer.enabled = NO;
[self scrollView].panGestureRecognizer.enabled = YES;
[self startBounceWithInitialVelocity:CGPointZero];
+
+ [self triggerHapticFeedbackForAction];
[self.delegate
overscrollActionsController:self
didTriggerAction:self.overscrollActionView.selectedAction];
}
+- (void)overscrollActionsView:(OverscrollActionsView*)view
+ selectedActionDidChange:(OverscrollAction)newAction {
+ [self triggerHapticFeedbackForSelectionChange];
+}
+
@end
« no previous file with comments | « no previous file | ios/chrome/browser/ui/overscroll_actions/overscroll_actions_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698