Dragula is a delightfully flexible and smooth drag-and-drop Swift package for building reorderable interfaces in SwiftUI. Inspired by Dracula's ability to move swiftly through the night (and by your need to reorder views), Dragula gives your lists and grids superpowers — with minimal code and maximum polish.
- 🔀 Reorder items within a list or across sections
- 🧱 Sectioned and unsectioned layouts
↔️ Horizontal and vertical scroll support- 🍞 Drop previews, haptics, and corner radius customization
- 🧩 UIKit-backed for pixel-perfect drag interaction
- iOS 16+
- Swift 5.8+
- Xcode 15+
Add Dragula via Swift Package Manager:
https://github.com/mufasayc/Dragula.git
struct MyItem: DragulaItem {
let id = UUID()
let title: String
}
struct MySection: DragulaSection {
let id = UUID()
let title: String
var items: [MyItem]
}DragulaView(items: $myItems) { item in
Text(item.title)
} dropView: { item in
Color.gray
} dropCompleted: {
// save the new order to db
}DragulaSectionedView(sections: $sections) { section in
Text(section.title)
} card: { item in
Text(item.title)
} dropView: { item in
Color.secondary
} dropCompleted: {
// save the new order to db
}Customize the drag preview appearance:
.environment(\.dragPreviewCornerRadius, 12)Check out ContentView.swift in the demo project to see:
- Vertical sectioned drag and drop
- Flat list reordering
- Horizontal drag views with scrolling
“I want to drag your views...” — Count Dragula
Built by Mustafa Yusuf
- A slight drag doesn't trigger
cancel, which appears to be a UIKit bug. A fix is in progress. - On Mac Catalyst,
cancelis not called inUIDragDelegatefor some reason — investigating this. - Plan to introduce a unified initializer in
DragulaViewto support both sectioned and flat lists. - Support for accepting drops containing items not already in the list will be added soon.
MIT License