freya-animation crate. Create smooth, declarative animations with support for numeric values, colors, sequential animations, and custom easing functions.
Basic Usage
Theuse_animation hook is the primary interface for creating animations:
Animation Types
AnimNum - Numeric Animations
Animate numeric values like positions, sizes, or rotations:AnimColor - Color Animations
Animate between colors smoothly:AnimSequential - Sequential Animations
Chain multiple animations to run one after another:Easing Functions
Control the animation timing with easing:Ease::In- Slow start, fast endEase::Out- Fast start, slow end (default)Ease::InOut- Slow start and end
Function::Linear- Constant speed (default)Function::Quad- Quadratic accelerationFunction::Cubic- Cubic accelerationFunction::Expo- Exponential accelerationFunction::Elastic- Elastic effectFunction::Bounce- Bouncing effectFunction::Back- Overshooting effectFunction::Circ- Circular accelerationFunction::Sine- Sinusoidal accelerationFunction::Quart- Quartic acceleration
Animation Control
Starting and Reversing
Animation Configuration
Control animation behavior withAnimConfiguration:
OnCreation Options
OnCreation::Nothing- Do nothing (default)OnCreation::Run- Start animation immediatelyOnCreation::Finish- Set to end state immediately
OnFinish Options
OnFinish::Nothing- Stop when complete (default)OnFinish::reverse()- Reverse directionOnFinish::reverse_with_delay(duration)- Reverse after delayOnFinish::restart()- Restart from beginningOnFinish::restart_with_delay(duration)- Restart after delay
Infinite Loop Animation
Dependencies and Transitions
With Dependencies
React to state changes:use_animation_with_dependencies for non-reactive dependencies:
OnChange Options
OnChange::Reset- Reset to initial state (default)OnChange::Finish- Jump to end stateOnChange::Rerun- Restart animationOnChange::Nothing- Do nothing
Transition Animations
Automatically animate between state values:Multiple Animations
Animate multiple values simultaneously using tuples:Animation State
Check animation status:Custom Animated Values
Implement theAnimatedValue trait for custom animation types:
Best Practices
- Use appropriate durations - 200-500ms for most UI animations
- Choose the right easing -
Ease::Outworks well for most cases - Prefer sequential over parallel - Use
AnimSequentialfor coordinated animations - Reset on unmount - Animations stop automatically when component unmounts
- Test performance - Complex animations may impact frame rate