Commit 30213814 authored by Kris Giesing's avatar Kris Giesing

Add hold and sweep semantics to gesture arena

parent 42469d2c
......@@ -45,6 +45,7 @@ class GestureArenaEntry {
class _GestureArenaState {
final List<GestureArenaMember> members = new List<GestureArenaMember>();
bool isOpen = true;
bool isHeld = false;
void add(GestureArenaMember member) {
assert(isOpen);
......@@ -72,6 +73,32 @@ class GestureArena {
_tryToResolveArena(key, state);
}
/// Force resolution on this arena, giving the win to the first member
void sweep(Object key) {
_GestureArenaState state = _arenas[key];
if (state == null)
return; // This arena either never existed or has been resolved.
assert(!state.isOpen);
if (state.isHeld)
return; // This arena is being held for a long-lived member
if (!state.members.isEmpty) {
// First member wins
state.members.first.acceptGesture(key);
// Give all the other members the bad news
for (int i = 1; i < state.members.length; i++)
state.members[i].rejectGesture(key);
}
_arenas.remove(key);
}
/// Prevent the arena from being swept
void hold(Object key) {
_GestureArenaState state = _arenas[key];
if (state == null)
return; // This arena either never existed or has been resolved.
state.isHeld = true;
}
void _tryToResolveArena(Object key, _GestureArenaState state) {
assert(_arenas[key] == state);
assert(!state.isOpen);
......
......@@ -167,6 +167,8 @@ class FlutterBinding extends HitTestTarget {
pointerRouter.route(event);
if (event.type == 'pointerdown')
GestureArena.instance.close(event.pointer);
else if (event.type == 'pointerup')
GestureArena.instance.sweep(event.pointer);
}
}
}
......
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