Skip to content

Commit 3496b1d

Browse files
authored
Add feedback for long press on iOS (#148922)
Adds the click system sound and heavy-impact haptic feedback to iOS on long presses. Fixes #148391
1 parent 53ced2a commit 3496b1d

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

packages/flutter/lib/src/widgets/feedback.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ import 'gesture_detector.dart';
2020
/// [wrapForTap] or [wrapForLongPress] to achieve the same (see example code
2121
/// below).
2222
///
23-
/// Calling any of these methods is a no-op on iOS as actions on that platform
24-
/// typically don't provide haptic or acoustic feedback.
25-
///
2623
/// All methods in this class are usually called from within a
2724
/// [StatelessWidget.build] method or from a [State]'s methods as you have to
2825
/// provide a [BuildContext].
@@ -127,8 +124,10 @@ abstract final class Feedback {
127124

128125
/// Provides platform-specific feedback for a long press.
129126
///
130-
/// On Android the platform-typical vibration is triggered. On iOS this is a
131-
/// no-op as that platform usually doesn't provide feedback for long presses.
127+
/// On Android the platform-typical vibration is triggered. On iOS a
128+
/// heavy-impact haptic feedback is triggered alongside the click system
129+
/// sound, which was observed to be the default behavior on a physical iPhone
130+
/// 15 Pro running iOS version 17.5.
132131
///
133132
/// See also:
134133
///
@@ -141,6 +140,10 @@ abstract final class Feedback {
141140
case TargetPlatform.fuchsia:
142141
return HapticFeedback.vibrate();
143142
case TargetPlatform.iOS:
143+
return Future.wait(<Future<void>>[
144+
SystemSound.play(SystemSoundType.click),
145+
HapticFeedback.heavyImpact()
146+
]);
144147
case TargetPlatform.linux:
145148
case TargetPlatform.macOS:
146149
case TargetPlatform.windows:
@@ -151,9 +154,10 @@ abstract final class Feedback {
151154
/// Wraps a [GestureLongPressCallback] to provide platform specific feedback
152155
/// for a long press before the provided callback is executed.
153156
///
154-
/// On Android the platform-typical vibration is triggered. On iOS this
155-
/// is a no-op as that platform usually doesn't provide feedback for a long
156-
/// press.
157+
/// On Android the platform-typical vibration is triggered. On iOS a
158+
/// heavy-impact haptic feedback is triggered alongside the click system
159+
/// sound, which was observed to be the default behavior on a physical iPhone
160+
/// 15 Pro running iOS version 17.5.
157161
///
158162
/// See also:
159163
///

packages/flutter/test/widgets/feedback_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ void main () {
190190

191191
await tester.longPress(find.text('X'));
192192
await tester.pumpAndSettle(kWaitDuration);
193-
expect(feedback.hapticCount, 0);
194-
expect(feedback.clickSoundCount, 0);
193+
expect(feedback.hapticCount, 1);
194+
expect(feedback.clickSoundCount, 1);
195195
},
196196
variant: TargetPlatformVariant.only(TargetPlatform.iOS));
197197
});

0 commit comments

Comments
 (0)