fix!: Remove pointerId from Draggable callbacks (#1313)

Since pointerId is already handled by the handle* methods we don't have to expose it in the onDrag* methods, this conforms with the standard set in Tappable.
This commit is contained in:
Lukas Klingsbo
2022-01-18 23:22:10 +01:00
committed by GitHub
parent b1d4e5872e
commit 27adda17b7
6 changed files with 49 additions and 27 deletions

View File

@ -180,13 +180,13 @@ abstract class MyCollidable extends PositionComponent
}
@override
bool onDragUpdate(int pointerId, _) {
bool onDragUpdate(_) {
_isDragged = true;
return true;
}
@override
bool onDragEnd(int pointerId, DragEndInfo info) {
bool onDragEnd(DragEndInfo info) {
velocity.setFrom(info.velocity / 10);
_isDragged = false;
return true;

View File

@ -49,13 +49,13 @@ class DraggableSquare extends Ember with Draggable {
}
@override
bool onDragStart(int pointerId, DragStartInfo info) {
bool onDragStart(DragStartInfo info) {
dragDeltaPosition = info.eventPosition.game - position;
return false;
}
@override
bool onDragUpdate(int pointerId, DragUpdateInfo info) {
bool onDragUpdate(DragUpdateInfo info) {
if (parent is! DraggablesExample) {
return true;
}
@ -69,13 +69,13 @@ class DraggableSquare extends Ember with Draggable {
}
@override
bool onDragEnd(int pointerId, _) {
bool onDragEnd(_) {
dragDeltaPosition = null;
return false;
}
@override
bool onDragCancel(int pointerId) {
bool onDragCancel() {
dragDeltaPosition = null;
return false;
}

View File

@ -108,24 +108,24 @@ class JoystickComponent extends HudMarginComponent with Draggable {
}
@override
bool onDragStart(int pointerId, DragStartInfo info) {
bool onDragStart(DragStartInfo info) {
return false;
}
@override
bool onDragUpdate(_, DragUpdateInfo info) {
bool onDragUpdate(DragUpdateInfo info) {
_unscaledDelta.add(info.delta.global);
return false;
}
@override
bool onDragEnd(int id, __) {
onDragCancel(id);
bool onDragEnd(_) {
onDragCancel();
return false;
}
@override
bool onDragCancel(_) {
bool onDragCancel() {
_unscaledDelta.setZero();
return false;
}

View File

@ -8,19 +8,41 @@ mixin Draggable on Component {
bool _isDragged = false;
bool get isDragged => _isDragged;
bool onDragStart(int pointerId, DragStartInfo info) {
/// Override this to handle the start of a drag/pan gesture that is within the
/// boundaries (determined by [Component.containsPoint]) of the component that
/// this mixin is used on.
/// Return `true` if you want this event to continue to be passed on to
/// components underneath (lower priority) this component.
bool onDragStart(DragStartInfo info) {
return true;
}
bool onDragUpdate(int pointerId, DragUpdateInfo info) {
/// Override this to handle the update of a drag/pan gesture that is within
/// the boundaries (determined by [Component.containsPoint]) of the component
/// that this mixin is used on.
/// Return `true` if you want this event to continue to be passed on to
/// components underneath (lower priority) this component.
bool onDragUpdate(DragUpdateInfo info) {
return true;
}
bool onDragEnd(int pointerId, DragEndInfo info) {
/// Override this to handle the end of a drag/pan gesture that is within
/// the boundaries (determined by [Component.containsPoint]) of the component
/// that this mixin is used on.
/// Return `true` if you want this event to continue to be passed on to
/// components underneath (lower priority) this component.
bool onDragEnd(DragEndInfo info) {
return true;
}
bool onDragCancel(int pointerId) {
/// Override this to handle if a drag/pan gesture is cancelled that was
/// previously started on the component that this mixin is used on.
/// Return `true` if you want this event to continue to be passed on to
/// components underneath (lower priority) this component.
///
/// This event is not that common, it can happen for example when the user
/// is interrupted by a system-modal dialog in the middle of the drag.
bool onDragCancel() {
return true;
}
@ -31,23 +53,23 @@ mixin Draggable on Component {
if (containsPoint(eventPosition(info))) {
_isDragged = true;
_currentPointerIds.add(pointerId);
return onDragStart(pointerId, info);
return onDragStart(info);
}
return true;
}
bool handleDragUpdated(int pointerId, DragUpdateInfo details) {
bool handleDragUpdated(int pointerId, DragUpdateInfo info) {
if (_checkPointerId(pointerId)) {
return onDragUpdate(pointerId, details);
return onDragUpdate(info);
}
return true;
}
bool handleDragEnded(int pointerId, DragEndInfo details) {
bool handleDragEnded(int pointerId, DragEndInfo info) {
if (_checkPointerId(pointerId)) {
_isDragged = false;
_currentPointerIds.remove(pointerId);
return onDragEnd(pointerId, details);
return onDragEnd(info);
}
return true;
}
@ -56,7 +78,7 @@ mixin Draggable on Component {
if (_checkPointerId(pointerId)) {
_isDragged = false;
_currentPointerIds.remove(pointerId);
return onDragCancel(pointerId);
return onDragCancel();
}
return true;
}

View File

@ -12,13 +12,13 @@ class _DraggableComponent extends PositionComponent with Draggable {
bool hasCanceledDragging = false;
@override
bool onDragStart(int pointerId, DragStartInfo info) {
bool onDragStart(DragStartInfo info) {
hasStartedDragging = true;
return true;
}
@override
bool onDragCancel(int pointerId) {
bool onDragCancel() {
hasCanceledDragging = true;
return true;
}

View File

@ -26,20 +26,20 @@ class DraggableBall extends Ball with Draggable {
}
@override
bool onDragStart(int pointerId, DragStartInfo details) {
bool onDragStart(DragStartInfo info) {
paint = randomPaint();
return true;
}
@override
bool onDragUpdate(int pointerId, DragUpdateInfo details) {
final worldDelta = Vector2(1, -1)..multiply(details.delta.game);
bool onDragUpdate(DragUpdateInfo info) {
final worldDelta = Vector2(1, -1)..multiply(info.delta.game);
body.applyLinearImpulse(worldDelta * 1000);
return true;
}
@override
bool onDragEnd(int pointerId, DragEndInfo details) {
bool onDragEnd(DragEndInfo info) {
paint = originalPaint;
return true;
}