onDragSessionUpdated
Specifies an action to perform on each update of an ongoing dragging operation activated by draggable(:) or anther drag modifiers.
Declaration
compose().onDragSessionUpdated(
onUpdate: (arg0: SwiftUI.DragSession) => void
)nonisolated func onDragSessionUpdated(
_ onUpdate: @escaping (DragSession) -> Void
) -> some ViewParameters
onUpdate*(arg0: SwiftUI.DragSession) => void
Discussion
Below is an example of a view that displays a book and supports
dragging to copy, move, and delete. If the session ends
with moving or deleting the item, in the onUpdate closure,
the view lets the model layer know that the book should be deleted
from the source.
struct DraggableBookView: View {
var id: UUID
var body: some View {
BookView()
.draggable(Book(id: id))
.dragConfiguration(
DragConfiguration(
operationsWithinApp: .init(allowMove: true, allowDelete: true),
operationsOutsideApp: .init(allowMove: true, allowDelete: true)
))
.onDragSessionUpdated { session in
switch session.phase {
case .ended(at: _, with: let operation):
if operation == .move || operation == .delete {
if let id = session.draggedItemIDs(type: UUID.self).first {
removeBook(id: id)
}
}
default:
break
}
}
}
}
func removeBook(id: UUID) { }The onUpdate closure is called when the closest drag session
in the child view hierarchy becomes active.
See also
More in Events and lifecycle.
- onAppearAdds an action to perform before this view appears.
- onChangeAdds a modifier for this view that fires an action when a specific value changes.
- onContinueUserActivityRegisters a handler to invoke in response to a user activity that your app receives.
- onContinuousHoverAdds an action to perform when the pointer enters, moves within, and exits the view's bounds.
- onDisappearAdds an action to perform after this view disappears.
- onDragActivates this view as the source of a drag and drop operation.
- onDropDefines the destination of a drag and drop operation that handles the dropped content with a closure that you specify.
- onDropSessionUpdatedSpecifies an action to perform on each update of an ongoing drop operation activated by dropDestination(:) or other drop modifiers.
- onGeometryChangeAdds an action to be performed when a value, created from a geometry proxy, changes.
- onHingeChangeAdds an action to perform when the hinge context of the view hierarchy changes.
- onHoverAdds an action to perform when the user moves the pointer over or away from the view's frame.
- onInteractiveResizeChangeAdds an action to perform when the enclosing window is being interactively resized.