One Logo Pool Ball
SwiftUICore · IOS API REFERENCE

Transaction

struct · iOS 13.0+ · SDK 27.1

@frozen struct Transaction

The context of the current state-processing update. Use a transaction to pass an animation between views in a view hierarchy. The root transaction for a state change comes from the binding that changed, plus any global values set by calling ``withTransaction(_:_:)`` or ``withAnimation(_:_:)``.

Members (17)

get · iOS 13.0+

isContinuous

TypeScript
get isContinuous(): boolean
Swift declaration
var isContinuous: Bool { get set }

A Boolean value that indicates whether the transaction originated from an action that produces a sequence of values. This value is `true` if a continuous action created the transaction, and is `false` otherwise. Continuous actions include things like dragging a slider or pressing and holding a stepper, as opposed to tapping a button.

set · iOS 13.0+

isContinuous

TypeScript
set isContinuous(value: boolean)
Swift declaration
var isContinuous: Bool { get set }

A Boolean value that indicates whether the transaction originated from an action that produces a sequence of values. This value is `true` if a continuous action created the transaction, and is `false` otherwise. Continuous actions include things like dragging a slider or pressing and holding a stepper, as opposed to tapping a button.

get · iOS 17.0+

tracksVelocity

TypeScript
get tracksVelocity(): boolean
Swift declaration
var tracksVelocity: Bool { get set }

Whether this transaction will track the velocity of any animatable properties that change. This property can be enabled in an interactive context to track velocity during a user interaction so that when the interaction ends, an animation can use the accumulated velocities to create animations that preserve them. This tracking is mutually exclusive with an animation being used during a view change, since if there is an animation, it is responsible for managing its own velocity. Gesture onChanged and updating callbacks automatically set this property to true. This example shows an interaction which applies changes, tracking velocity until the final change, which applies an animation (which will start with the velocity that was tracked during the previous changes). These changes could come from a server or from an interactive control like a slider. func receiveChange(change: ChangeInfo) { var transaction = Transaction() if change.isFinal { transaction.animation = .spring } else { transaction.tracksVelocity = true } withTransaction(transaction) { state.applyChange(change) } }

set · iOS 17.0+

tracksVelocity

TypeScript
set tracksVelocity(value: boolean)
Swift declaration
var tracksVelocity: Bool { get set }

Whether this transaction will track the velocity of any animatable properties that change. This property can be enabled in an interactive context to track velocity during a user interaction so that when the interaction ends, an animation can use the accumulated velocities to create animations that preserve them. This tracking is mutually exclusive with an animation being used during a view change, since if there is an animation, it is responsible for managing its own velocity. Gesture onChanged and updating callbacks automatically set this property to true. This example shows an interaction which applies changes, tracking velocity until the final change, which applies an animation (which will start with the velocity that was tracked during the previous changes). These changes could come from a server or from an interactive control like a slider. func receiveChange(change: ChangeInfo) { var transaction = Transaction() if change.isFinal { transaction.animation = .spring } else { transaction.tracksVelocity = true } withTransaction(transaction) { state.applyChange(change) } }

get · iOS 13.0+

disablesAnimations

TypeScript
get disablesAnimations(): boolean
Swift declaration
var disablesAnimations: Bool { get set }

A Boolean value that indicates whether views should disable animations. This value is `true` during the initial phase of a two-part transition update, to prevent ``View/animation(_:)`` from inserting new animations into the transaction.

set · iOS 13.0+

disablesAnimations

TypeScript
set disablesAnimations(value: boolean)
Swift declaration
var disablesAnimations: Bool { get set }

A Boolean value that indicates whether views should disable animations. This value is `true` during the initial phase of a two-part transition update, to prevent ``View/animation(_:)`` from inserting new animations into the transaction.

get · iOS 17.0+

scrollTargetAnchor

TypeScript
get scrollTargetAnchor(): (UnitPoint) | null
Swift declaration
var scrollTargetAnchor: UnitPoint? { get set }

The preferred alignment of the view within a scroll view's visible region when scrolling to a view. Use this API in conjunction with a ``ScrollViewProxy/scrollTo(_:anchor)`` or when updating the binding provided to a ``View/scrollPosition(id:anchor:)``. @Binding var position: Item.ID? var body: some View { ScrollView { LazyVStack { ForEach(items) { item in ItemView(item) } } .scrollTargetLayout() } .scrollPosition(id: $position) .safeAreaInset(edge: .bottom) { Button("Scroll To Bottom") { withAnimation { withTransaction(\.scrollTargetAnchor, .bottom) { position = items.last?.id } } } } } When used with the ``View/scrollPosition(id:anchor:)`` modifier, this value will be preferred over the anchor specified in the modifier for the current transaction.

set · iOS 17.0+

scrollTargetAnchor

TypeScript
set scrollTargetAnchor(value: (UnitPoint) | null)
Swift declaration
var scrollTargetAnchor: UnitPoint? { get set }

The preferred alignment of the view within a scroll view's visible region when scrolling to a view. Use this API in conjunction with a ``ScrollViewProxy/scrollTo(_:anchor)`` or when updating the binding provided to a ``View/scrollPosition(id:anchor:)``. @Binding var position: Item.ID? var body: some View { ScrollView { LazyVStack { ForEach(items) { item in ItemView(item) } } .scrollTargetLayout() } .scrollPosition(id: $position) .safeAreaInset(edge: .bottom) { Button("Scroll To Bottom") { withAnimation { withTransaction(\.scrollTargetAnchor, .bottom) { position = items.last?.id } } } } } When used with the ``View/scrollPosition(id:anchor:)`` modifier, this value will be preferred over the anchor specified in the modifier for the current transaction.

method · iOS 17.0+

addAnimationCompletion

TypeScript
addAnimationCompletion(criteria: AnimationCompletionCriteria, completion: (() => void)): void
Swift declaration
mutating func addAnimationCompletion(criteria: AnimationCompletionCriteria = .logicallyComplete, _ completion: @escaping () -> Void)

Adds a completion to run when the animations created with this transaction are all complete. The completion callback will always be fired exactly one time. If no animations are created by the changes in `body`, then the callback will be called immediately after `body`.

get · iOS 18.0+

scrollContentOffsetAdjustmentBehavior

TypeScript
get scrollContentOffsetAdjustmentBehavior(): ScrollContentOffsetAdjustmentBehavior
Swift declaration
var scrollContentOffsetAdjustmentBehavior: ScrollContentOffsetAdjustmentBehavior { get set }

The behavior a scroll view will have regarding content offset adjustments for the current transaction. A scroll view may automatically adjust its content offset based on the current context. The absolute offset may be adjusted to keep content in relatively the same place. For example, when scrolled to the bottom, a scroll view may keep the bottom edge scrolled to the bottom when the overall size of its content changes. Use this property to disable these kinds of adjustments when needed.

set · iOS 18.0+

scrollContentOffsetAdjustmentBehavior

TypeScript
set scrollContentOffsetAdjustmentBehavior(value: ScrollContentOffsetAdjustmentBehavior)
Swift declaration
var scrollContentOffsetAdjustmentBehavior: ScrollContentOffsetAdjustmentBehavior { get set }

The behavior a scroll view will have regarding content offset adjustments for the current transaction. A scroll view may automatically adjust its content offset based on the current context. The absolute offset may be adjusted to keep content in relatively the same place. For example, when scrolled to the bottom, a scroll view may keep the bottom edge scrolled to the bottom when the overall size of its content changes. Use this property to disable these kinds of adjustments when needed.

get · iOS 18.0+

scrollPositionUpdatePreservesVelocity

TypeScript
get scrollPositionUpdatePreservesVelocity(): boolean
Swift declaration
var scrollPositionUpdatePreservesVelocity: Bool { get set }

Whether a programmatic update to the scroll position of a scroll view preserves the current velocity of any active scroll of the scroll view. By default, when a scroll view sees a programmatic update to its scroll position, it will stop any active scrolls for unanimated scrolls. If a programmatic update is animated, this property is ignored.

set · iOS 18.0+

scrollPositionUpdatePreservesVelocity

TypeScript
set scrollPositionUpdatePreservesVelocity(value: boolean)
Swift declaration
var scrollPositionUpdatePreservesVelocity: Bool { get set }

Whether a programmatic update to the scroll position of a scroll view preserves the current velocity of any active scroll of the scroll view. By default, when a scroll view sees a programmatic update to its scroll position, it will stop any active scrolls for unanimated scrolls. If a programmatic update is animated, this property is ignored.

get · iOS 13.0+

animation

TypeScript
get animation(): (Animation) | null
Swift declaration
var animation: Animation? { get set }

The animation, if any, associated with the current state change.

set · iOS 13.0+

animation

TypeScript
set animation(value: (Animation) | null)
Swift declaration
var animation: Animation? { get set }

The animation, if any, associated with the current state change.

init · iOS 13.0+

init

TypeScript
static initAnimation(animation?: (Animation) | null): Transaction
Swift declaration
init(animation: Animation?)

Creates a transaction and assigns its animation property. - Parameter animation: The animation to perform when the current state changes.

init · iOS 13.0+

init

TypeScript
static init(): Transaction
Swift declaration
init()

Creates a transaction.

Skipped declarations

1 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

Transaction.subscript(_:)

Passing a Swift type itself is not supported.

All SwiftUICore types →