Implicit .animation() vs explicit withAnimation
WHAT IT TESTS: How SwiftUI ties animation to state changes. OUTLINE: .animation(value:) animates a view when a tracked value changes; withAnimation wraps the state mutation so all dependent views animate.
WHAT IT TESTS: Understanding where you attach animation: to a view or to a state change. ANSWER OUTLINE: The implicit .animation(_:value:) modifier lives on a view and animates that view whenever the supplied value changes, scoped to that subtree. withAnimation wraps a state mutation in a closure, so every view that depends on the changed state animates together with the given curve. Use implicit for a single self-contained component; use explicit when one action should coordinate several views.
Read the original → interview
- #ios
- #swiftui
- #animation
- #state
- #ui
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.