Spring class determines the timing curve and settling duration of animations using real spring physics.
Creating springs
Wave provides two ways to create springs: usingresponse (frequency-based) or stiffness (force-based).
- Response (recommended)
- Stiffness
response represents the frequency response of the spring - essentially the duration of one period in the spring’s undamped system, measured in seconds.- Values closer to
0create very fast animations - Values closer to
1.0create relatively slower animations
Response and stiffness are interchangeable - Wave automatically converts between them using the formula:
stiffness = (2π / response)² × massSpring parameters
Damping ratio
ThedampingRatio controls the amount of oscillation (“springiness”) in your animation:
1.0(critically damped): Smoothly reaches the target value without any oscillation or overshoot< 1.0(underdamped): Increases oscillation and overshoots the target before settling> 1.0(overdamped): Slower animation with no oscillation
Spring physics behind damping ratio
Spring physics behind damping ratio
When
dampingRatio = 1.0, the spring is critically damped - it reaches equilibrium as quickly as possible without oscillating.Values below 1.0 are underdamped and will overshoot the target, creating a bouncy effect. The lower the damping ratio, the more oscillation cycles occur before settling.The damping coefficient c is derived from the damping ratio using:Response
Theresponse affects how quickly the spring animation reaches its target:
Mass
Themass parameter represents the mass “attached” to the spring. The default value of 1.0 rarely needs modification:
Derived properties
Wave automatically calculates additional properties from your spring configuration:Default springs
Wave provides three pre-configured springs for common scenarios:Settling duration
ThesettlingDuration tells you how long the spring will take to complete. This is automatically calculated based on your spring parameters:
Real-world examples
Here are spring configurations from Wave’s sample app:Choosing spring values
Start with defaults
Use
Spring.defaultInteractive for gesture-driven animations or Spring.defaultAnimated for triggered animations.Adjust damping ratio
Set to
1.0 for smooth animations without bounce, or 0.6-0.8 for slight bounciness.Tune response
Lower values (0.2-0.3) for tight, responsive animations. Higher values (0.6-1.0) for more relaxed motion.
Advanced: Spring physics formulas
For those interested in the underlying physics, Wave uses these formulas:Spring.swift:128-156 and ensure physically accurate spring behavior.