[@expo/ui] Add withAnimation function
D
Denys Hrychulevych
I'm using @expo/ui/swift-ui to build native SwiftUI interfaces in my Expo app. Currently, the library supports the animation modifier, but there's no way to trigger imperative animations like SwiftUI's withAnimation function.
Use Case:
When implementing matchedGeometryEffect for hero transitions between screens, animations need to be triggered at specific moments (e.g., when navigating). SwiftUI's withAnimation allows wrapping state changes to animate them:
withAnimation {
isExpanded = true
}
Currently, the animation modifier only applies automatic animations based on value changes, but doesn't provide control over when the animation should happen.
Proposed API:
import { withAnimation, Animation } from "@expo/ui/swift-ui";
withAnimation(Animation.default, () => {
setIsExpanded(true);
});
Why this matters:
- Essential for smooth hero transitions with matchedGeometryEffect
- Enables parity with native SwiftUI animation patterns
- Allows fine-grained control over animation timing and triggers
- Makes complex coordinated animations possible
- This would greatly improve the animation capabilities of @expo/ui and enable truly native-feeling transitions in React Native apps.