Skip to content

[DragOverlay] Dont do drop animation if its not moved? #2104

Description

@hashfiputra

As the title said, I tried with this:

  const dropAnimation: DropAnimation = async (context) => {
    const { feedbackElement, translate, moved } = context;
    if (!moved) return;

    const duration = 250;
    const start = performance.now();
    const ease = cubicBezier(0.25, 0.1, 0.25, 1.0);

    await new Promise<void>((resolve) => {
      function tick(now: number) {
        const valid = feedbackElement instanceof HTMLElement;
        const time = Math.min((now - start) / duration, 1);
        const eased = ease(time);
        if (!valid) return;

        const x = translate.x * (1 - eased);
        const y = translate.y * (1 - eased);
        feedbackElement.style.setProperty("--dnd-translate", `${x}px ${y}px`);

        if (time < 1) requestAnimationFrame(tick);
        if (time >= 1) resolve();
      }

      requestAnimationFrame(tick);
    });
  };

But it come with edge case I cant seem to fix, for example if I sort my element and the position changed, the overlay will be drop to its old position. Why I want to disable drop animation if its not moved? In my opinion if its not moved it will still ran the animation it will look like it "lagged" even though it run a drop animation, like its standing still. Have any solve for this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    domDOM packageenhancementNew feature or requestreactReact package

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions