computerjazz / react-native-draggable-flatlist

A drag-and-drop-enabled FlatList for React Native
MIT License
1.92k stars 402 forks source link

Drag disabled for falsy keys #521

Closed codercody closed 6 months ago

codercody commented 8 months ago

I encountered this issue when I made a NestableDraggableFlatList with an array that looks like [{title: 'a', key: 0}, {title: 'b', key: 1}, {title: 'c', key: 2}]. I noticed that I could never drag the first element, but it did enlarge as it was wrapped in a ScaleDecorator. I realized it's because of this line in the source code, which doesn't enable dragging if your key is falsy:

https://github.com/computerjazz/react-native-draggable-flatlist/blob/ebfddc4877e8f65d5391a748db61b9cd030430ba/src/components/DraggableFlatList.tsx#L121

Instead, it should check if activeKey is null or undefined.

My current fix is to 1-index my keys rather than 0-index.

computerjazz commented 6 months ago

sounds like you may be using array index as key? see pitfall section here: https://react.dev/learn/rendering-lists#why-does-react-need-keys

please use non-empty strings as keys