🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

react-native-reanimated-dnd

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-reanimated-dnd

A powerful drag-and-drop library for React Native using Reanimated 3

1.0.5
latest
Source
npm
Version published
Weekly downloads
7.9K
307.74%
Maintainers
1
Weekly downloads
 
Created
Source

React Native Reanimated DnD 🎯

React Native Reanimated DnD Demo

A drag-and-drop library that finally works on React Native

Powerful, performant, and built for the modern React Native developer

npm version License: MIT TypeScript React Native


Documentation Live Demo

🚀 Why This Library?

After countless attempts with drag-and-drop solutions that don't work or are simply outdated, this is something that finally works. And it is not just another DnD library, but a complete ecosystem built from the ground up for React Native, offering a best-in-class developer experience and production-ready performance.

Highly feature-packed with every interaction pattern you'll ever need, yet simple enough to get started in minutes. Built for developers who demand both power and simplicity.

✨ Features

  • 🚀 High Performance - Built with Reanimated 3 for buttery-smooth 60fps animations
  • 🎯 Flexible API - From simple drag-and-drop to complex sortable lists
  • 📱 React Native First - Designed specifically for mobile, not ported from web
  • 🔧 TypeScript Ready - Full type safety with comprehensive definitions
  • 🎨 Infinitely Customizable - Every animation, behavior, and style is configurable
  • 📦 Complete Component Suite - Draggable, Droppable, Sortable, and more
  • 🎪 Smart Collision Detection - Multiple algorithms (center, intersect, contain)
  • 📜 Sortable Lists - Drag and drop to sort a Vertical List, also supports Automatic scrolling for out of screen dragging
  • 🎭 Drag Handles - Precise control with dedicated drag areas
  • 🎬 Custom Animations - Spring, timing, or bring your own animation functions
  • 📐 Pixel-Perfect Positioning - 9-point alignment system with custom offsets
  • 📦 Boundary Constraints - Keep draggables within specific areas
  • State Management - Complete lifecycle tracking and callbacks
  • 🎯 Developer Experience - Intuitive APIs, helpful warnings, and extensive examples

📱 Interactive Examples

See it in action! A comprehensive example app with 15 interactive demos showcasing every feature and use case.

🎮 Try the Example App

📱 Scan & Play

Expo QR Code

Scan with your camera or Expo Go app

🚀 Quick Start

  • Install Expo Go on your phone
  • Scan the QR code with your camera
  • Open the link in Expo Go
  • Explore 15 interactive examples!

Or browse the code: 📂 View Example App →

📚 Complete Documentation

Documentation

Comprehensive guides, API reference, and interactive examples

The example app includes:

  • 🎵 Sortable Music Queue - Complete list reordering with handles
  • 🎯 Collision Detection - Different algorithms in action
  • 🎬 Custom Animations - Spring, timing, and easing variations
  • 📦 Boundary Constraints - Axis-locked and bounded dragging
  • Visual Feedback - Active styles and state management
  • ⚙️ Advanced Patterns - Custom implementations and hooks

🎬 Video Showcase

See the library in action with these demos showcasing some of the key features and use cases.

📋 Sortable Lists

Drag and drop to reorder items with smooth animations

https://github.com/user-attachments/assets/1cd1929c-724b-4dda-a916-f3e69f917f7b

Features: Auto-scrolling • Drag handles • Smooth transitions

🎯 Collision Detection

Multiple algorithms for precise drop targeting

https://github.com/user-attachments/assets/379040d7-8489-430b-bae4-3fcbde34264e

Algorithms: Center • Intersect • Contain

🎪 Drag Handles

Precise control with dedicated drag areas

https://github.com/user-attachments/assets/ec051d5b-8ba0-41b7-86ae-379de26a97dd

Features: Touch-friendly • Visual feedback • Accessibility

📦 Bounded Dragging

Constrain movement within specific boundaries

https://github.com/user-attachments/assets/7bd5045b-47c4-4d9b-a0c5-eb89122ec9c0

Constraints: Axis-locked • Container bounds • Custom limits

✨ Active Drop Styles

Visual feedback during drag operations

https://github.com/user-attachments/assets/3b8a3d00-38ad-4532-bd42-173037ea61b9

Feedback: Hover states • Drop zones • Visual cues

🔄 State Management

Complete lifecycle tracking and callbacks

https://github.com/user-attachments/assets/da5e526f-f2d2-4dc5-96b5-3fecc4faf57a

States: Idle • Dragging • Animating • Dropped

🚀 Installation

npm install react-native-reanimated-dnd

Peer Dependencies

npm install react-native-reanimated react-native-gesture-handler

Follow the setup guides:

🏃‍♂️ Quick Start

Basic Draggable

import React from "react";
import { View, Text } from "react-native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { Draggable, DropProvider } from "react-native-reanimated-dnd";

export default function App() {
  return (
    <GestureHandlerRootView style={{ flex: 1 }}>
      <DropProvider>
        <View style={{ flex: 1, padding: 20 }}>
          <Draggable data={{ id: "1", title: "Drag me!" }}>
            <View
              style={{
                padding: 20,
                backgroundColor: "#007AFF",
                borderRadius: 8,
              }}
            >
              <Text style={{ color: "white" }}>Drag me around!</Text>
            </View>
          </Draggable>
        </View>
      </DropProvider>
    </GestureHandlerRootView>
  );
}

Drag & Drop with Multiple Zones

import React from "react";
import { View, Text } from "react-native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import {
  Draggable,
  Droppable,
  DropProvider,
} from "react-native-reanimated-dnd";

export default function DragDropExample() {
  const handleDrop = (data: any) => {
    console.log("Item dropped:", data);
  };

  return (
    <GestureHandlerRootView style={{ flex: 1 }}>
      <DropProvider>
        <View style={{ flex: 1, padding: 20 }}>
          {/* Draggable Item */}
          <Draggable data={{ id: "1", title: "Drag me!" }}>
            <View style={styles.draggableItem}>
              <Text>📦 Drag me to a zone</Text>
            </View>
          </Draggable>

          {/* Drop Zones */}
          <Droppable onDrop={handleDrop}>
            <View style={styles.dropZone}>
              <Text>🎯 Drop Zone 1</Text>
            </View>
          </Droppable>

          <Droppable onDrop={handleDrop}>
            <View style={styles.dropZone}>
              <Text>🎯 Drop Zone 2</Text>
            </View>
          </Droppable>
        </View>
      </DropProvider>
    </GestureHandlerRootView>
  );
}

Sortable List

import React, { useState } from "react";
import { View, Text } from "react-native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { Sortable, SortableItem } from "react-native-reanimated-dnd";

interface Task {
  id: string;
  title: string;
}

export default function SortableExample() {
  const [tasks, setTasks] = useState<Task[]>([
    { id: "1", title: "Learn React Native" },
    { id: "2", title: "Build an app" },
    { id: "3", title: "Deploy to store" },
  ]);

  const renderTask = ({ item, id, positions, ...props }) => (
    <SortableItem
      key={id}
      id={id}
      positions={positions}
      {...props}
      onMove={(itemId, from, to) => {
        const newTasks = [...tasks];
        const [movedTask] = newTasks.splice(from, 1);
        newTasks.splice(to, 0, movedTask);
        setTasks(newTasks);
      }}
    >
      <View style={styles.taskItem}>
        <Text>{item.title}</Text>

        {/* Drag Handle */}
        <SortableItem.Handle style={styles.dragHandle}>
          <Text>⋮⋮</Text>
        </SortableItem.Handle>
      </View>
    </SortableItem>
  );

  return (
    <GestureHandlerRootView style={{ flex: 1 }}>
      <Sortable
        data={tasks}
        renderItem={renderTask}
        itemHeight={60}
        style={{ flex: 1, padding: 16 }}
      />
    </GestureHandlerRootView>
  );
}

📚 API Reference

Components

<Draggable>

Makes any component draggable with extensive customization options.

<Draggable
  data={any}                                    // Data associated with the item
  onDragStart={(data) => void}                  // Called when dragging starts
  onDragEnd={(data) => void}                    // Called when dragging ends
  onDragging={(position) => void}               // Called during dragging
  onStateChange={(state) => void}               // Called on state changes
  dragDisabled={boolean}                        // Disable dragging
  collisionAlgorithm="center|intersect|contain" // Collision detection method
  dragAxis="x|y|both"                          // Constrain movement axis
  dragBoundsRef={RefObject}                    // Boundary container reference
  animationFunction={(toValue) => Animation}    // Custom animation function
  style={StyleProp<ViewStyle>}                 // Component styling
>
  {children}
</Draggable>

<Droppable>

Creates drop zones with visual feedback and capacity management.

<Droppable
  onDrop={(data) => void}                      // Called when item is dropped
  onActiveChange={(isActive) => void}          // Called on hover state change
  dropDisabled={boolean}                       // Disable drop functionality
  dropAlignment="top-left|center|bottom-right|..." // Drop positioning
  dropOffset={{ x: number, y: number }}       // Position offset
  activeStyle={StyleProp<ViewStyle>}           // Style when active
  capacity={number}                            // Maximum items allowed
  droppableId={string}                         // Unique identifier
>
  {children}
</Droppable>

<Sortable>

High-level component for sortable lists with auto-scrolling.

<Sortable
  data={Array<{ id: string }>} // Array of items to render
  renderItem={(props) => ReactNode} // Render function for items
  itemHeight={number} // Height of each item
  itemKeyExtractor={(item) => string} // Custom key extractor
  style={StyleProp<ViewStyle>} // List container style
  contentContainerStyle={StyleProp<ViewStyle>} // Content container style
/>

<SortableItem>

Individual item within a sortable list with gesture handling.

<SortableItem
  id={string}                                 // Unique identifier
  data={any}                                  // Item data
  positions={SharedValue}                     // Position tracking
  onMove={(id, from, to) => void}            // Called when item moves
  onDragStart={(id, position) => void}       // Called when dragging starts
  onDrop={(id, position) => void}            // Called when item is dropped
  onDragging={(id, overItemId, y) => void}   // Called during dragging
  style={StyleProp<ViewStyle>}               // Item styling
  animatedStyle={StyleProp<AnimatedStyle>}   // Animated styling
>
  {children}
</SortableItem>

Hooks

useDraggable(options)

Core hook for implementing draggable functionality.

useDroppable(options)

Core hook for implementing droppable functionality.

useSortable(options)

Hook for individual sortable items with position management.

useSortableList(options)

Hook for managing entire sortable lists with auto-scrolling.

Context

<DropProvider>

Required context provider that manages global drag-and-drop state.

<DropProvider>{/* All draggable and droppable components */}</DropProvider>

Types & Enums

DraggableState

enum DraggableState {
  IDLE = "idle",
  DRAGGING = "dragging",
  ANIMATING = "animating",
}

CollisionAlgorithm

type CollisionAlgorithm = "center" | "intersect" | "contain";

DropAlignment

type DropAlignment =
  | "top-left"
  | "top-center"
  | "top-right"
  | "center-left"
  | "center"
  | "center-right"
  | "bottom-left"
  | "bottom-center"
  | "bottom-right";

🎨 Advanced Usage

Custom Animations

import { withTiming, withSpring, Easing } from "react-native-reanimated";

// Smooth timing animation
const smoothAnimation = (toValue) => {
  "worklet";
  return withTiming(toValue, {
    duration: 300,
    easing: Easing.bezier(0.25, 0.1, 0.25, 1),
  });
};

// Spring animation
const springAnimation = (toValue) => {
  "worklet";
  return withSpring(toValue, {
    damping: 15,
    stiffness: 150,
  });
};

<Draggable animationFunction={springAnimation}>{/* content */}</Draggable>;

Collision Detection Strategies

// Precise center-point collision
<Draggable collisionAlgorithm="center">
  {/* Requires center point to be over drop zone */}
</Draggable>

// Forgiving intersection collision (default)
<Draggable collisionAlgorithm="intersect">
  {/* Any overlap triggers collision */}
</Draggable>

// Strict containment collision
<Draggable collisionAlgorithm="contain">
  {/* Entire draggable must be within drop zone */}
</Draggable>

Drag Handles

<SortableItem id={item.id} {...props}>
  <View style={styles.itemContainer}>
    <Text>{item.title}</Text>

    {/* Only this handle area can initiate dragging */}
    <SortableItem.Handle style={styles.dragHandle}>
      <View style={styles.handleIcon}>
        <View style={styles.dot} />
        <View style={styles.dot} />
        <View style={styles.dot} />
      </View>
    </SortableItem.Handle>
  </View>
</SortableItem>

Bounded Dragging

const containerRef = useRef<View>(null);

<View ref={containerRef} style={styles.container}>
  <Draggable
    data={data}
    dragBoundsRef={containerRef}
    dragAxis="x" // Constrain to horizontal movement
  >
    {/* content */}
  </Draggable>
</View>;

Drop Zone Capacity

<Droppable
  capacity={3}
  onDrop={(data) => {
    if (currentItems.length < 3) {
      addItem(data);
    }
  }}
  activeStyle={{
    backgroundColor: currentItems.length < 3 ? "#e8f5e8" : "#ffe8e8",
  }}
>
  <Text>Drop Zone ({currentItems.length}/3)</Text>
</Droppable>

🏃‍♂️ Running the Example App

  • Clone the repository:
git clone https://github.com/entropyconquers/react-native-reanimated-dnd.git
cd react-native-reanimated-dnd
  • Install dependencies:
npm install
cd example-app
npm install
  • Run the example app:
# iOS
npx expo run:ios

# Android
npx expo run:android

The example app includes all 15 interactive examples showcasing every feature of the library.

🤝 Contributing

Contributions are always welcome! Please see our Contributing Guide for details.

📄 License

MIT © Vishesh Raheja

🙏 Acknowledgments

  • Built with React Native Reanimated for smooth 60fps animations
  • Gesture handling powered by React Native Gesture Handler
  • Inspired by the React ecosystem's drag-and-drop libraries
  • Special thanks to the React Native community for feedback and contributions

Made with ❤️ for the React Native community

⭐ Star on GitHub📱 Try the Demo📖 Documentation

Keywords

react-native

FAQs

Package last updated on 28 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts