DynamicViewContent ModifieriOS 16.0+macOS 13.0+tvOS 16.0+watchOS 9.0+dropDestination(for:action:) in SwiftUI
Declaration
compose().dropDestination<T>({
action: (arg0: T[], arg1: number) => void,
})nonisolated func dropDestination<T>(
for payloadType: T.Type = T.self,
action: @escaping ([T], Int) -> Void
) -> some DynamicViewContent
where T : TransferableParameters
options.action*(arg0: T[], arg1: number) => voidA closure that SwiftUI invokes when elements are added to the view. The closure takes two arguments: The first argument is the offset relative to the dynamic view's underlying collection of data. The second argument is an array of
Transferableitems that represents the data that you want to insert.
Return value
A view that calls action when elements are inserted into the original view.
Discussion
struct Profile: Identifiable {
let givenName: String
let familyName: String
let id = UUID()
}
@State private var profiles: [Profile] = [
Person(givenName: "Juan", familyName: "Chavez"),
Person(givenName: "Mei", familyName: "Chen"),
Person(givenName: "Tom", familyName: "Clark"),
Person(givenName: "Gita", familyName: "Kumar")
]
var body: some View {
List {
ForEach(profiles) { profile in
Text(profile.givenName)
}
.dropDestination(for: Profile.self) { receivedProfiles, offset in
profiles.insert(contentsOf: receivedProfiles, at: offset)
}
}
}See also
More in DynamicViewContent modifiers.
- onDeleteSets the deletion action for the dynamic view. You must delete the corresponding item within action, as it will be called after the row has already been removed from the List.
- onMoveSets the move action for the dynamic view.
- reorderableEnables reordering of views from this content inside the scope of a reorderable container modifier.