Commit d61f7809 authored by Andrew Wilson's avatar Andrew Wilson

Merge pull request #3012 from apwilson/leave

Leave all entered targets when finishing.
parents d8155347 f516dbcc
...@@ -391,7 +391,7 @@ class _DragAvatar<T> extends Drag { ...@@ -391,7 +391,7 @@ class _DragAvatar<T> extends Drag {
final _OnDragEnd onDragEnd; final _OnDragEnd onDragEnd;
_DragTargetState<T> _activeTarget; _DragTargetState<T> _activeTarget;
List<_DragTargetState<T>> _lastTargets = <_DragTargetState<T>>[]; List<_DragTargetState<T>> _enteredTargets = <_DragTargetState<T>>[];
Point _position; Point _position;
Offset _lastOffset; Offset _lastOffset;
OverlayEntry _entry; OverlayEntry _entry;
...@@ -422,12 +422,12 @@ class _DragAvatar<T> extends Drag { ...@@ -422,12 +422,12 @@ class _DragAvatar<T> extends Drag {
List<_DragTargetState<T>> targets = _getDragTargets(result.path).toList(); List<_DragTargetState<T>> targets = _getDragTargets(result.path).toList();
bool listsMatch = false; bool listsMatch = false;
if (targets.length >= _lastTargets.length && _lastTargets.isNotEmpty) { if (targets.length >= _enteredTargets.length && _enteredTargets.isNotEmpty) {
listsMatch = true; listsMatch = true;
Iterator<_DragTargetState<T>> iterator = targets.iterator; Iterator<_DragTargetState<T>> iterator = targets.iterator;
for (int i = 0; i < _lastTargets.length; i += 1) { for (int i = 0; i < _enteredTargets.length; i += 1) {
iterator.moveNext(); iterator.moveNext();
if (iterator.current != _lastTargets[i]) { if (iterator.current != _enteredTargets[i]) {
listsMatch = false; listsMatch = false;
break; break;
} }
...@@ -439,13 +439,11 @@ class _DragAvatar<T> extends Drag { ...@@ -439,13 +439,11 @@ class _DragAvatar<T> extends Drag {
return; return;
// Leave old targets. // Leave old targets.
for (int i = 0; i < _lastTargets.length; i += 1) _leaveAllEntered();
_lastTargets[i].didLeave(data);
_lastTargets.clear();
// Enter new targets. // Enter new targets.
_DragTargetState<T> newTarget = targets.firstWhere((_DragTargetState<T> target) { _DragTargetState<T> newTarget = targets.firstWhere((_DragTargetState<T> target) {
_lastTargets.add(target); _enteredTargets.add(target);
return target.didEnter(data); return target.didEnter(data);
}, },
orElse: () => null orElse: () => null
...@@ -466,16 +464,20 @@ class _DragAvatar<T> extends Drag { ...@@ -466,16 +464,20 @@ class _DragAvatar<T> extends Drag {
} }
} }
void _leaveAllEntered() {
for (int i = 0; i < _enteredTargets.length; i += 1)
_enteredTargets[i].didLeave(data);
_enteredTargets.clear();
}
void finish(_DragEndKind endKind, [Velocity velocity]) { void finish(_DragEndKind endKind, [Velocity velocity]) {
bool wasAccepted = false; bool wasAccepted = false;
if (_activeTarget != null) {
if (endKind == _DragEndKind.dropped && _activeTarget != null) { if (endKind == _DragEndKind.dropped && _activeTarget != null) {
_activeTarget.didDrop(data); _activeTarget.didDrop(data);
wasAccepted = true; wasAccepted = true;
} else { _enteredTargets.remove(_activeTarget);
_activeTarget.didLeave(data);
}
} }
_leaveAllEntered();
_activeTarget = null; _activeTarget = null;
_entry.remove(); _entry.remove();
_entry = null; _entry = null;
......
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