reorderable()
Enables the views of this content to be reordered when used within the scope of a Reordercontainer(for:in:isenabled:move:) modifier.
Declaration
nonisolated func reorderable() -> some DynamicViewContent<Self.Data>
Mentioned in
Discussion
Declare this modifier on DynamicViewContent within a reorderable container to allow your users to reorder the items in the content using a system drag gesture.
Provide a collection identifier when you have multiple collections in the container and need to uniquely refer to each one. If your container only has a single collection, you can use the default identifier.
This example shows a list of landmarks. Items can be moved within the view’s underlying collection.
struct ContentView: View {
@State private var landmarks: [Landmark] = []
var body: some View {
VStack {
ForEach(landmarks) { landmark in
LandmarkView(landmark)
}
.reorderable()
}
.reorderContainer(for: Landmark.self) { difference in
difference.apply(to: &landmarks)
}
}
}See Also
Reordering items
Making a card game with drag, drop, and reordering in SwiftUIreorderable(collectionID:)ReorderableSingleCollectionIdentifierreorderContainer(for:isEnabled:move:)reorderContainer(for:in:isEnabled:move:)reorderContainer(for:itemID:isEnabled:move:)reorderContainer(for:itemID:in:isEnabled:move:)reorderDestination(for:in:)reorderDestination(for:itemID:in:)ReorderDifference