Drag to Sort with Reanimated and Gesture Handler ๐ŸคŒ๐Ÿฝ

Wednesday, December 20, 2023
reanimated
gesture-handler
A list component that allows reordering through drag and drop gestures. Includes visual feedback and position tracking.

What's This About?

This component creates a list where:
  • Items can be dragged to reorder
  • Visual feedback shows current position
  • Items adjust their shape while dragging
  • Gradient overlay adds depth

Technical Implementation

The component uses:
  • Reanimated for drag gestures
  • Custom list implementation for z-index handling
  • Position tracking with shared values
  • Linear gradient overlay
  • Safe area handling

Usage

type Item = {
id: string;
title: string;
// other item properties
};
// Basic usage
<SortableList
data={items}
listItemHeight={80}
onDragEnd={(positions) => {
console.log('New order:', positions);
}}
renderItem={({ item, index }) => (
<ListItem
item={item}
index={index}
style={{
height: 80,
margin: 6,
}}
/>
)}
/>;

Unlock the beauty of React Native animations

Learn Reanimated, Gesture Handler & Skia with Reanimate.dev

Drag To Sort - Feedback

Share Your Thoughts

I value a lot your feedback! Help me improve by sharing your thoughts, suggestions, or reporting any issues you encounter. If you need assistance, send me an email at hello@reactiive.io