Skip to content
This repository was archived by the owner on Feb 18, 2022. It is now read-only.
This repository was archived by the owner on Feb 18, 2022. It is now read-only.

Sorting callback // use optional order attribute to sort the children #7

@Harti

Description

@Harti

First of all, thanks for creating this! I've been desperately waiting for Ryan Florence to update his MagicMove library but it just wouldn't happen. So I'm really glad you stepped in and did some refactoring while at it.

I've got a pesky issue with your lib though: The children sorting. From both your example and the sources I assume that the ordering of child elements within the Shuffle container will be made by "greater-than" comparisons using the component's key attribute.
This seems to produce issues as React appears to use the key attribute as a unique identifier for a component.

Let me elaborate. Imagine the following racing situation UI:

[driverID: 3, pos: 3] <--- 1.8 s ---> [driverID: 2, pos: 2] <--- 0.7 s ---> [driverID: 1, pos: 1]

Since the drivers don't change in this scenario their IDs are used as the component's key attribute. React-shuffle would reorder my list and mess the position order up (3 being greater than 2, 2 being greater than 1).
As a workaround I use key={1000-pos} to get the right order. (we'll revisit this later)

I want to animate this inline-block list whenever any driver overtakes another driver, resulting in a position change. Like so:

[driverID: 3, pos: 3] <--- 2.1 s ---> [driverID: **1**, pos: 2] <--- 0.1 s ---> [driverID: **2**, pos: 1]

(the divs containing drivers 1&2 information are supposed to change positions in an animated way)

However, since I'm using {1000-pos} as the key attribute, the drivers are no longer considered the unique components. Therefore, React will merely swap the affected components' contents instead of actually rearranging the components. And thus, React-Shuffle won't animate anything because it was not the driver components' order that changed but their contents.

Introducing support for an attribute to order Shuffle's children, or for replacing the proprietary sorting function, could probably solve this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions