Add GestureArena

In the GestureArena, gestures will fight it out to see which is the real
ultimate gesture.
This commit is contained in:
Adam Barth
2015-08-27 17:07:24 -07:00
parent ce51289616
commit d8de2f9770
2 changed files with 132 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
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);
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);
});
}