Declaration
compose().springLoadingBehavior(
behavior: SwiftUI.SpringLoadingBehavior
)nonisolated func springLoadingBehavior(
_ behavior: SpringLoadingBehavior
) -> some ViewParameters
behavior*SwiftUI.SpringLoadingBehaviorWhether spring loading is enabled or not. If unspecified, the default behavior is
.automatic.
Discussion
Spring loading refers to a view being activated during a drag and drop interaction. On iOS this can occur when pausing briefly on top of a view with dragged content. On macOS this can occur with similar brief pauses or on pressure-sensitive systems by "force clicking" during the drag. This has no effect on tvOS or watchOS.
This is commonly used with views that have a navigation or presentation effect, allowing the destination to be revealed without pausing the drag interaction. For example, a button that reveals a list of folders that a dragged item can be dropped onto.
Button {
showFolders = true
} label: {
Label("Show Folders", systemImage: "folder")
}
.springLoadingBehavior(.enabled)Unlike disabled(_:), this modifier overrides the value set by an
ancestor view rather than being unioned with it. For example, the below
button would allow spring loading:
HStack {
Button {
showFolders = true
} label: {
Label("Show Folders", systemImage: "folder")
}
.springLoadingBehavior(.enabled)
...
}
.springLoadingBehavior(.disabled)See also
More in Animation.
- animationApplies the given animation to all animatable values within the body closure.
- contentTransitionModifies the view to use a given transition as its method of animating changes to the contents of its views.
- glassEffectTransitionAssociates a glass effect transition with any glass effects defined within this view.
- keyframeAnimatorLoops the given keyframes continuously, updating the view using the modifiers you apply in body.
- matchedGeometryEffectDefines a group of views with synchronized geometry using an identifier and namespace that you provide.
- matchedTransitionSourceIdentifies this view as the source of a navigation transition, such as a zoom transition.
- phaseAnimatorAnimates effects that you apply to a view over a sequence of phases that change continuously.
- scrollTransitionApplies the given transition, animating between the phases of the transition as this view appears and disappears within the visible region of the containing scroll view.
- transitionAssociates a transition with the view.