Unverified Commit 92a1a8ba authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Migrate to FlutterView.gestureSettings (#121749)

parent 5cf1e5f7
...@@ -26,7 +26,7 @@ class DeviceGestureSettings { ...@@ -26,7 +26,7 @@ class DeviceGestureSettings {
/// Create a new [DeviceGestureSettings] from the provided [view]. /// Create a new [DeviceGestureSettings] from the provided [view].
factory DeviceGestureSettings.fromView(ui.FlutterView view) { factory DeviceGestureSettings.fromView(ui.FlutterView view) {
final double? physicalTouchSlop = view.viewConfiguration.gestureSettings.physicalTouchSlop; final double? physicalTouchSlop = view.gestureSettings.physicalTouchSlop;
return DeviceGestureSettings( return DeviceGestureSettings(
touchSlop: physicalTouchSlop == null ? null : physicalTouchSlop / view.devicePixelRatio touchSlop: physicalTouchSlop == null ? null : physicalTouchSlop / view.devicePixelRatio
); );
......
...@@ -90,9 +90,7 @@ class NestedDraggableCase extends StatelessWidget { ...@@ -90,9 +90,7 @@ class NestedDraggableCase extends StatelessWidget {
void main() { void main() {
testWidgets('Scroll Views get the same ScrollConfiguration as GestureDetectors', (WidgetTester tester) async { testWidgets('Scroll Views get the same ScrollConfiguration as GestureDetectors', (WidgetTester tester) async {
tester.binding.window.viewConfigurationTestValue = const ui.ViewConfiguration( tester.binding.window.gestureSettingsTestValue = const ui.GestureSettings(physicalTouchSlop: 4);
gestureSettings: ui.GestureSettings(physicalTouchSlop: 4),
);
final TestResult result = TestResult(); final TestResult result = TestResult();
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
...@@ -110,12 +108,12 @@ void main() { ...@@ -110,12 +108,12 @@ void main() {
expect(result.dragStarted, true); expect(result.dragStarted, true);
expect(result.dragUpdate, true); expect(result.dragUpdate, true);
tester.binding.window.clearGestureSettingsTestValue();
}); });
testWidgets('Scroll Views get the same ScrollConfiguration as Draggables', (WidgetTester tester) async { testWidgets('Scroll Views get the same ScrollConfiguration as Draggables', (WidgetTester tester) async {
tester.binding.window.viewConfigurationTestValue = const ui.ViewConfiguration( tester.binding.window.gestureSettingsTestValue = const ui.GestureSettings(physicalTouchSlop: 4);
gestureSettings: ui.GestureSettings(physicalTouchSlop: 4),
);
final TestResult result = TestResult(); final TestResult result = TestResult();
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
...@@ -133,5 +131,6 @@ void main() { ...@@ -133,5 +131,6 @@ void main() {
expect(result.dragStarted, true); expect(result.dragStarted, true);
expect(result.dragUpdate, true); expect(result.dragUpdate, true);
tester.binding.window.clearGestureSettingsTestValue();
}); });
} }
...@@ -1326,12 +1326,10 @@ void main() { ...@@ -1326,12 +1326,10 @@ void main() {
}); });
testWidgets('MediaQueryData.gestureSettings is set from window.viewConfiguration', (WidgetTester tester) async { testWidgets('MediaQueryData.gestureSettings is set from window.viewConfiguration', (WidgetTester tester) async {
tester.binding.window.viewConfigurationTestValue = const ViewConfiguration( tester.binding.window.gestureSettingsTestValue = const GestureSettings(physicalDoubleTapSlop: 100, physicalTouchSlop: 100);
gestureSettings: GestureSettings(physicalDoubleTapSlop: 100, physicalTouchSlop: 100),
);
expect(MediaQueryData.fromView(tester.binding.window).gestureSettings.touchSlop, closeTo(33.33, 0.1)); // Repeating, of course expect(MediaQueryData.fromView(tester.binding.window).gestureSettings.touchSlop, closeTo(33.33, 0.1)); // Repeating, of course
tester.binding.window.viewConfigurationTestValue = null; tester.binding.window.clearGestureSettingsTestValue();
}); });
testWidgets('MediaQuery can be partially depended-on', (WidgetTester tester) async { testWidgets('MediaQuery can be partially depended-on', (WidgetTester tester) async {
...@@ -1544,6 +1542,8 @@ class TestView implements FlutterView { ...@@ -1544,6 +1542,8 @@ class TestView implements FlutterView {
final ViewConfiguration viewConfiguration = const ViewConfiguration(); final ViewConfiguration viewConfiguration = const ViewConfiguration();
@override @override
final List<DisplayFeature> displayFeatures = <DisplayFeature>[]; final List<DisplayFeature> displayFeatures = <DisplayFeature>[];
@override
final GestureSettings gestureSettings = const GestureSettings();
@override @override
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
......
...@@ -143,6 +143,20 @@ class TestWindow implements ui.SingletonFlutterWindow { ...@@ -143,6 +143,20 @@ class TestWindow implements ui.SingletonFlutterWindow {
onMetricsChanged?.call(); onMetricsChanged?.call();
} }
@override
ui.GestureSettings get gestureSettings => _gestureSettings ?? _window.gestureSettings;
ui.GestureSettings? _gestureSettings;
/// Hides the real gesture settings and reports the given [gestureSettingsTestValue] instead.
set gestureSettingsTestValue(ui.GestureSettings gestureSettingsTestValue) { // ignore: avoid_setters_without_getters
_gestureSettings = gestureSettingsTestValue;
onMetricsChanged?.call();
}
/// Deletes any existing test gesture settings and returns to using the real gesture settings.
void clearGestureSettingsTestValue() {
_paddingTestValue = null;
onMetricsChanged?.call();
}
@override @override
List<ui.DisplayFeature> get displayFeatures => _displayFeaturesTestValue ?? _window.displayFeatures; List<ui.DisplayFeature> get displayFeatures => _displayFeaturesTestValue ?? _window.displayFeatures;
List<ui.DisplayFeature>? _displayFeaturesTestValue; List<ui.DisplayFeature>? _displayFeaturesTestValue;
...@@ -508,6 +522,7 @@ class TestWindow implements ui.SingletonFlutterWindow { ...@@ -508,6 +522,7 @@ class TestWindow implements ui.SingletonFlutterWindow {
void clearAllTestValues() { void clearAllTestValues() {
clearDevicePixelRatioTestValue(); clearDevicePixelRatioTestValue();
clearPaddingTestValue(); clearPaddingTestValue();
clearGestureSettingsTestValue();
clearDisplayFeaturesTestValue(); clearDisplayFeaturesTestValue();
clearPhysicalSizeTestValue(); clearPhysicalSizeTestValue();
clearViewInsetsTestValue(); clearViewInsetsTestValue();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment