Skip to content

Commit 92a1a8b

Browse files
authored
Migrate to FlutterView.gestureSettings (#121749)
1 parent 5cf1e5f commit 92a1a8b

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

packages/flutter/lib/src/gestures/gesture_settings.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DeviceGestureSettings {
2626

2727
/// Create a new [DeviceGestureSettings] from the provided [view].
2828
factory DeviceGestureSettings.fromView(ui.FlutterView view) {
29-
final double? physicalTouchSlop = view.viewConfiguration.gestureSettings.physicalTouchSlop;
29+
final double? physicalTouchSlop = view.gestureSettings.physicalTouchSlop;
3030
return DeviceGestureSettings(
3131
touchSlop: physicalTouchSlop == null ? null : physicalTouchSlop / view.devicePixelRatio
3232
);

packages/flutter/test/gestures/gesture_config_regression_test.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ class NestedDraggableCase extends StatelessWidget {
9090

9191
void main() {
9292
testWidgets('Scroll Views get the same ScrollConfiguration as GestureDetectors', (WidgetTester tester) async {
93-
tester.binding.window.viewConfigurationTestValue = const ui.ViewConfiguration(
94-
gestureSettings: ui.GestureSettings(physicalTouchSlop: 4),
95-
);
93+
tester.binding.window.gestureSettingsTestValue = const ui.GestureSettings(physicalTouchSlop: 4);
9694
final TestResult result = TestResult();
9795

9896
await tester.pumpWidget(MaterialApp(
@@ -110,12 +108,12 @@ void main() {
110108

111109
expect(result.dragStarted, true);
112110
expect(result.dragUpdate, true);
111+
tester.binding.window.clearGestureSettingsTestValue();
113112
});
114113

115114
testWidgets('Scroll Views get the same ScrollConfiguration as Draggables', (WidgetTester tester) async {
116-
tester.binding.window.viewConfigurationTestValue = const ui.ViewConfiguration(
117-
gestureSettings: ui.GestureSettings(physicalTouchSlop: 4),
118-
);
115+
tester.binding.window.gestureSettingsTestValue = const ui.GestureSettings(physicalTouchSlop: 4);
116+
119117
final TestResult result = TestResult();
120118

121119
await tester.pumpWidget(MaterialApp(
@@ -133,5 +131,6 @@ void main() {
133131

134132
expect(result.dragStarted, true);
135133
expect(result.dragUpdate, true);
134+
tester.binding.window.clearGestureSettingsTestValue();
136135
});
137136
}

packages/flutter/test/widgets/media_query_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,12 +1326,10 @@ void main() {
13261326
});
13271327

13281328
testWidgets('MediaQueryData.gestureSettings is set from window.viewConfiguration', (WidgetTester tester) async {
1329-
tester.binding.window.viewConfigurationTestValue = const ViewConfiguration(
1330-
gestureSettings: GestureSettings(physicalDoubleTapSlop: 100, physicalTouchSlop: 100),
1331-
);
1329+
tester.binding.window.gestureSettingsTestValue = const GestureSettings(physicalDoubleTapSlop: 100, physicalTouchSlop: 100);
13321330

13331331
expect(MediaQueryData.fromView(tester.binding.window).gestureSettings.touchSlop, closeTo(33.33, 0.1)); // Repeating, of course
1334-
tester.binding.window.viewConfigurationTestValue = null;
1332+
tester.binding.window.clearGestureSettingsTestValue();
13351333
});
13361334

13371335
testWidgets('MediaQuery can be partially depended-on', (WidgetTester tester) async {
@@ -1544,6 +1542,8 @@ class TestView implements FlutterView {
15441542
final ViewConfiguration viewConfiguration = const ViewConfiguration();
15451543
@override
15461544
final List<DisplayFeature> displayFeatures = <DisplayFeature>[];
1545+
@override
1546+
final GestureSettings gestureSettings = const GestureSettings();
15471547

15481548
@override
15491549
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);

packages/flutter_test/lib/src/window.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@ class TestWindow implements ui.SingletonFlutterWindow {
143143
onMetricsChanged?.call();
144144
}
145145

146+
@override
147+
ui.GestureSettings get gestureSettings => _gestureSettings ?? _window.gestureSettings;
148+
ui.GestureSettings? _gestureSettings;
149+
/// Hides the real gesture settings and reports the given [gestureSettingsTestValue] instead.
150+
set gestureSettingsTestValue(ui.GestureSettings gestureSettingsTestValue) { // ignore: avoid_setters_without_getters
151+
_gestureSettings = gestureSettingsTestValue;
152+
onMetricsChanged?.call();
153+
}
154+
/// Deletes any existing test gesture settings and returns to using the real gesture settings.
155+
void clearGestureSettingsTestValue() {
156+
_paddingTestValue = null;
157+
onMetricsChanged?.call();
158+
}
159+
146160
@override
147161
List<ui.DisplayFeature> get displayFeatures => _displayFeaturesTestValue ?? _window.displayFeatures;
148162
List<ui.DisplayFeature>? _displayFeaturesTestValue;
@@ -508,6 +522,7 @@ class TestWindow implements ui.SingletonFlutterWindow {
508522
void clearAllTestValues() {
509523
clearDevicePixelRatioTestValue();
510524
clearPaddingTestValue();
525+
clearGestureSettingsTestValue();
511526
clearDisplayFeaturesTestValue();
512527
clearPhysicalSizeTestValue();
513528
clearViewInsetsTestValue();

0 commit comments

Comments
 (0)