Improving Animations on iOS with Stagehand
Article Summary
Cash App just open-sourced Stagehand, their solution to a problem that's plagued iOS developers since 2008: building animations shouldn't feel like archaeology.
Nick Entin from Cash App traces the messy evolution of iOS animation APIs (from CoreAnimation's stringly-typed key paths to UIKit blocks) and introduces their modern Swift framework that finally brings compile-time safety and composability to animation development.
Key Takeaways
- Stagehand uses Swift key paths for compile-time safe animations, no more type-erased values
- Composable structure lets you build complex multi-part animations from reusable components
- Construction separates from execution: define animations before creating the views to animate
- Visual snapshot testing for animations catches regressions with GIF comparisons
- Works with custom types via protocol conformance, not just views and layers
Cash App's Stagehand framework brings modern Swift patterns to iOS animations with compile-time safety, composability, and visual snapshot testing built in.
About This Article
iOS animation APIs haven't changed much since iOS 4.0. Developers end up picking between UIKit's block-based approach and CoreAnimation's stringly-typed key paths. These two don't work well together when you need complex animations.
Nick Entin's team at Cash App built Stagehand with Swift generics and protocol conformance. It lets you animate any type, not just views and layers. Type safety comes from key path-based keyframe definitions.
Stagehand uses snapshot testing to generate animated GIFs of entire animations. This catches animation regressions by letting you visually verify how animations behave when code changes.