Scrolls should start immediately when possible
If there are no other gestures in the arena, we should kick off the scroll gesture right away. This change pulled a refactoring of how we dispatch events to Widgets. Now we dispatch events to Widgets interleaved with their associated RenderObjects. (Previously we dispatched to all of the RenderObjects first.)
This commit is contained in:
58
packages/unit/test/widget/gesture_detector_test.dart
Normal file
58
packages/unit/test/widget/gesture_detector_test.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
import 'package:sky/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../engine/mock_events.dart';
|
||||
import 'widget_tester.dart';
|
||||
|
||||
void main() {
|
||||
test('Uncontested scrolls start immediately', () {
|
||||
WidgetTester tester = new WidgetTester();
|
||||
TestPointer pointer = new TestPointer(7);
|
||||
|
||||
bool didStartScroll = false;
|
||||
double updatedScrollDelta;
|
||||
bool didEndScroll = false;
|
||||
|
||||
Widget builder() {
|
||||
return new GestureDetector(
|
||||
onVerticalScrollStart: () {
|
||||
didStartScroll = true;
|
||||
},
|
||||
onVerticalScrollUpdate: (double scrollDelta) {
|
||||
updatedScrollDelta = scrollDelta;
|
||||
},
|
||||
onVerticalScrollEnd: () {
|
||||
didEndScroll = true;
|
||||
},
|
||||
child: new Container()
|
||||
);
|
||||
}
|
||||
|
||||
tester.pumpFrame(builder);
|
||||
expect(didStartScroll, isFalse);
|
||||
expect(updatedScrollDelta, isNull);
|
||||
expect(didEndScroll, isFalse);
|
||||
|
||||
Point firstLocation = new Point(10.0, 10.0);
|
||||
tester.dispatchEvent(pointer.down(firstLocation), firstLocation);
|
||||
expect(didStartScroll, isTrue);
|
||||
didStartScroll = false;
|
||||
expect(updatedScrollDelta, isNull);
|
||||
expect(didEndScroll, isFalse);
|
||||
|
||||
Point secondLocation = new Point(10.0, 9.0);
|
||||
tester.dispatchEvent(pointer.move(secondLocation), secondLocation);
|
||||
expect(didStartScroll, isFalse);
|
||||
expect(updatedScrollDelta, 1.0);
|
||||
updatedScrollDelta = null;
|
||||
expect(didEndScroll, isFalse);
|
||||
|
||||
tester.dispatchEvent(pointer.up(), secondLocation);
|
||||
expect(didStartScroll, isFalse);
|
||||
expect(updatedScrollDelta, isNull);
|
||||
expect(didEndScroll, isTrue);
|
||||
didEndScroll = false;
|
||||
|
||||
tester.pumpFrame(() => new Container());
|
||||
});
|
||||
}
|
||||
@@ -89,29 +89,22 @@ class WidgetTester {
|
||||
return SkyBinding.instance.dispatchEvent(event, result);
|
||||
}
|
||||
|
||||
void tap(Widget widget) {
|
||||
void tap(Widget widget, { int pointer: 1 }) {
|
||||
Point location = getCenter(widget);
|
||||
HitTestResult result = _hitTest(location);
|
||||
_dispatchEvent(new TestPointerEvent(type: 'pointerdown', x: location.x, y: location.y), result);
|
||||
_dispatchEvent(new TestPointerEvent(type: 'pointerup', x: location.x, y: location.y), result);
|
||||
TestPointer p = new TestPointer(pointer);
|
||||
_dispatchEvent(p.down(location), result);
|
||||
_dispatchEvent(p.up(), result);
|
||||
}
|
||||
|
||||
void scroll(Widget widget, Offset offset) {
|
||||
void scroll(Widget widget, Offset offset, { int pointer: 1 }) {
|
||||
Point startLocation = getCenter(widget);
|
||||
HitTestResult result = _hitTest(startLocation);
|
||||
_dispatchEvent(new TestPointerEvent(type: 'pointerdown', x: startLocation.x, y: startLocation.y), result);
|
||||
Point endLocation = startLocation + offset;
|
||||
_dispatchEvent(
|
||||
new TestPointerEvent(
|
||||
type: 'pointermove',
|
||||
x: endLocation.x,
|
||||
y: endLocation.y,
|
||||
dx: offset.dx,
|
||||
dy: offset.dy
|
||||
),
|
||||
result
|
||||
);
|
||||
_dispatchEvent(new TestPointerEvent(type: 'pointerup', x: endLocation.x, y: endLocation.y), result);
|
||||
HitTestResult result = _hitTest(startLocation);
|
||||
TestPointer p = new TestPointer(pointer);
|
||||
_dispatchEvent(p.down(startLocation), result);
|
||||
_dispatchEvent(p.move(endLocation), result);
|
||||
_dispatchEvent(p.up(), result);
|
||||
}
|
||||
|
||||
void dispatchEvent(sky.Event event, Point location) {
|
||||
|
||||
Reference in New Issue
Block a user