reorderable(collectionID:)
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(collectionID: some Hashable & Sendable) -> 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 sectioned list of reminders:
struct ContentView: View {
@State private var model = ReminderModel()
var body: some View {
List {
ForEach(model.sections) { section in
Section(section.name) {
ForEach(section.reminders) { reminder in
ReminderView(reminder)
}
.reorderable(collectionID: section.id)
}
}
}
.reorderContainer(
for: Reminder.self, in: ReminderModel.Section.ID.self
) { difference in
model.apply(difference: difference)
}
}
}collectionID: The identifier that represents this collection. Its value is used in the destination value when reordering.
See Also
Reordering items
Making a card game with drag, drop, and reordering in SwiftUIreorderable()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