Member-only story
Transactions in SwiftUI
Manage Animations
View updates and animations in SwiftUI can be managed through transactions.
This article runs through transactions, what they are and why you might want to use them.
What are transactions?
Transaction can be used to pass animation between views in a view hierarchy.
That pretty much means that they are used to manage and customise the behaviour of animations, providing a way to override animation-related properties during state updates.
Key Features of Transactions
Transactions give granular control over animations within a view hierarchy.
They allow you to modify default animations or customise specific animation properties.
Use of Transactions
Dynamic Animation Based on Scale
Here is an example where an image scales up when tapped. The animation type changes dynamically depending on the current applied scale, and if it exceeds 1.5 a spring animation is used, unless an ease-in-out animation is used.
struct ContentView: View {
@State private var scale: CGFloat = 1.0
var body: some View {
VStack {…