Moves drag:move emission to animation loop
Ensures drag:move events are emitted during the animation loop for smoother and more consistent updates during drag operations. Removes redundant emission from the main drag handling logic.
This commit is contained in:
parent
9b073a15b7
commit
0764437642
1 changed files with 25 additions and 14 deletions
|
|
@ -298,19 +298,6 @@ export class DragDropManager {
|
|||
this.currentY = parseFloat(this.draggedClone!.style.top) || 0;
|
||||
this.animateDrag();
|
||||
}
|
||||
|
||||
// Emit drag:move event with current draggedClone reference
|
||||
if (this.draggedClone) {
|
||||
const dragMovePayload: DragMoveEventPayload = {
|
||||
draggedElement: this.draggedElement!,
|
||||
draggedClone: this.draggedClone,
|
||||
mousePosition: currentPosition,
|
||||
snappedY: this.currentY,
|
||||
columnBounds: column,
|
||||
mouseOffset: this.mouseOffset
|
||||
};
|
||||
this.eventBus.emit('drag:move', dragMovePayload);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for auto-scroll
|
||||
|
|
@ -478,7 +465,7 @@ export class DragDropManager {
|
|||
|
||||
/**
|
||||
* Smooth drag animation using requestAnimationFrame
|
||||
* Only interpolates currentY - events are emitted from continueDrag()
|
||||
* Emits drag:move events with current draggedClone reference on each frame
|
||||
*/
|
||||
private animateDrag(): void {
|
||||
if (!this.isDragStarted || !this.draggedClone || !this.targetColumn) {
|
||||
|
|
@ -493,10 +480,34 @@ export class DragDropManager {
|
|||
// Update if difference is significant
|
||||
if (Math.abs(diff) > 0.5) {
|
||||
this.currentY += step;
|
||||
|
||||
// Emit drag:move event with current draggedClone reference
|
||||
const dragMovePayload: DragMoveEventPayload = {
|
||||
draggedElement: this.draggedElement!,
|
||||
draggedClone: this.draggedClone, // Always uses current reference
|
||||
mousePosition: this.lastMousePosition,
|
||||
snappedY: this.currentY,
|
||||
columnBounds: this.targetColumn,
|
||||
mouseOffset: this.mouseOffset
|
||||
};
|
||||
this.eventBus.emit('drag:move', dragMovePayload);
|
||||
|
||||
this.dragAnimationId = requestAnimationFrame(() => this.animateDrag());
|
||||
} else {
|
||||
// Close enough - snap to target
|
||||
this.currentY = this.targetY;
|
||||
|
||||
// Emit final position
|
||||
const dragMovePayload: DragMoveEventPayload = {
|
||||
draggedElement: this.draggedElement!,
|
||||
draggedClone: this.draggedClone,
|
||||
mousePosition: this.lastMousePosition,
|
||||
snappedY: this.currentY,
|
||||
columnBounds: this.targetColumn,
|
||||
mouseOffset: this.mouseOffset
|
||||
};
|
||||
this.eventBus.emit('drag:move', dragMovePayload);
|
||||
|
||||
this.dragAnimationId = null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue