mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

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.)
70 lines
1.8 KiB
Dart
70 lines
1.8 KiB
Dart
import 'package:sky/gestures/arena.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
typedef void GestureArenaCallback(Object key);
|
|
|
|
class TestGestureArenaMember extends GestureArenaMember {
|
|
TestGestureArenaMember({ this.onAcceptGesture, this.onRejectGesture });
|
|
|
|
final GestureArenaCallback onAcceptGesture;
|
|
final GestureArenaCallback onRejectGesture;
|
|
|
|
void acceptGesture(Object key) {
|
|
onAcceptGesture(key);
|
|
}
|
|
|
|
void rejectGesture(Object key) {
|
|
onRejectGesture(key);
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
test('Should win by accepting', () {
|
|
GestureArena arena = new GestureArena();
|
|
|
|
int primaryKey = 4;
|
|
bool firstAcceptRan = false;
|
|
bool firstRejectRan = false;
|
|
bool secondAcceptRan = false;
|
|
bool secondRejectRan = false;
|
|
|
|
TestGestureArenaMember first = new TestGestureArenaMember(
|
|
onAcceptGesture: (int key) {
|
|
expect(key, equals(primaryKey));
|
|
firstAcceptRan = true;
|
|
},
|
|
onRejectGesture: (int key) {
|
|
expect(key, equals(primaryKey));
|
|
firstRejectRan = true;
|
|
}
|
|
);
|
|
|
|
TestGestureArenaMember second = new TestGestureArenaMember(
|
|
onAcceptGesture: (int key) {
|
|
expect(key, equals(primaryKey));
|
|
secondAcceptRan = true;
|
|
},
|
|
onRejectGesture: (int key) {
|
|
expect(key, equals(primaryKey));
|
|
secondRejectRan = true;
|
|
}
|
|
);
|
|
|
|
GestureArenaEntry firstEntry = arena.add(primaryKey, first);
|
|
arena.add(primaryKey, second);
|
|
arena.close(primaryKey);
|
|
|
|
expect(firstAcceptRan, isFalse);
|
|
expect(firstRejectRan, isFalse);
|
|
expect(secondAcceptRan, isFalse);
|
|
expect(secondRejectRan, isFalse);
|
|
|
|
firstEntry.resolve(GestureDisposition.accepted);
|
|
|
|
expect(firstAcceptRan, isTrue);
|
|
expect(firstRejectRan, isFalse);
|
|
expect(secondAcceptRan, isFalse);
|
|
expect(secondRejectRan, isTrue);
|
|
});
|
|
}
|