DragAndDropKit allows you to implement drag and drop functionality easily in your SwiftUI projects without any effort.
import SwiftUI
import DragAndDropKit
struct DragAndDropPractice: View {
@State var items: [Item] = Array(1...20).map { Item(id: $0) }
@State var currentDragging: Item? = nil
var body: some View {
ScrollView {
LazyVStack(content: {
ForEach(items, id: \.self) { item in
Text("Placeholder \(item.id)")
.padding()
.frame(maxWidth: .infinity)
.frame(height: 100)
.background(Color.gray.opacity(0.6))
.dragAndDrop(
item: item,
items: $items,
currentDragging: $currentDragging)
}
})
}
}
}
struct Item: Identifiable, Hashable {
let id: Int
}