From 361730ed72903103e270c1d99f07bcb5df6649ed Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Fri, 9 Aug 2019 15:45:15 -0700 Subject: [PATCH] iOS 13 scrollbar vibration (#37724) Vibrate when starting scrollbar dragging. --- .../flutter/lib/src/cupertino/scrollbar.dart | 3 +++ .../test/cupertino/scrollbar_test.dart | 24 +++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/cupertino/scrollbar.dart b/packages/flutter/lib/src/cupertino/scrollbar.dart index eb66fbf452..f80356cf8e 100644 --- a/packages/flutter/lib/src/cupertino/scrollbar.dart +++ b/packages/flutter/lib/src/cupertino/scrollbar.dart @@ -5,6 +5,7 @@ import 'dart:async'; import 'package:flutter/gestures.dart'; +import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; // All values eyeballed. @@ -207,6 +208,7 @@ class _CupertinoScrollbarState extends State with TickerProv _assertVertical(); _fadeoutTimer?.cancel(); _fadeoutAnimationController.forward(); + HapticFeedback.mediumImpact(); _dragScrollbar(details.localPosition.dy); _dragScrollbarPositionY = details.localPosition.dy; } @@ -234,6 +236,7 @@ class _CupertinoScrollbarState extends State with TickerProv _assertVertical(); _fadeoutTimer?.cancel(); _thicknessAnimationController.forward(); + HapticFeedback.mediumImpact(); _dragScrollbar(details.localPosition.dy); _dragScrollbarPositionY = details.localPosition.dy; } diff --git a/packages/flutter/test/cupertino/scrollbar_test.dart b/packages/flutter/test/cupertino/scrollbar_test.dart index 5abdac781f..ceb37c2aa3 100644 --- a/packages/flutter/test/cupertino/scrollbar_test.dart +++ b/packages/flutter/test/cupertino/scrollbar_test.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'package:flutter/cupertino.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import '../rendering/mock_canvas.dart'; @@ -86,9 +87,18 @@ void main() { await scrollGesture.up(); await tester.pump(); - // Longpress on the scrollbar thumb. + int hapticFeedbackCalls = 0; + SystemChannels.platform.setMockMethodCallHandler((MethodCall methodCall) async { + if (methodCall.method == 'HapticFeedback.vibrate') { + hapticFeedbackCalls++; + } + }); + + // Longpress on the scrollbar thumb and expect a vibration. + expect(hapticFeedbackCalls, 0); final TestGesture dragScrollbarGesture = await tester.startGesture(const Offset(796.0, 50.0)); await tester.pump(const Duration(milliseconds: 500)); + expect(hapticFeedbackCalls, 1); // Drag the thumb down to scroll down. await dragScrollbarGesture.moveBy(const Offset(0.0, scrollAmount)); @@ -145,11 +155,21 @@ void main() { await scrollGesture.up(); await tester.pump(); - // Drag in from the right side on top of the scrollbar thumb. + int hapticFeedbackCalls = 0; + SystemChannels.platform.setMockMethodCallHandler((MethodCall methodCall) async { + if (methodCall.method == 'HapticFeedback.vibrate') { + hapticFeedbackCalls++; + } + }); + + // Drag in from the right side on top of the scrollbar thumb and expect a + // vibration. + expect(hapticFeedbackCalls, 0); final TestGesture dragScrollbarGesture = await tester.startGesture(const Offset(796.0, 50.0)); await tester.pump(); await dragScrollbarGesture.moveBy(const Offset(-50.0, 0.0)); await tester.pump(_kScrollbarResizeDuration); + expect(hapticFeedbackCalls, 1); // Drag the thumb down to scroll down. await dragScrollbarGesture.moveBy(const Offset(0.0, scrollAmount));