Dioxus Motion 🚀
A lightweight, cross-platform animation library for Dioxus, designed to bring smooth, flexible animations to your Rust web, desktop, and mobile applications.
🎯 Live Examples
Visit our Example Website to see these animations in action:
🚀 Page Transitions
use *;
And replace all your Outlet::<Route> {} with AnimatedOutlet::<Route> {} and place the layout containing OutletRouter on top with something like this
Each route can have its own transition effect:
Fade: Smooth opacity transitionZoomIn: Scale and fade combinationSlideLeft: Horizontal slide animation- And more!
- Also, add transitions feature to support page transitions. Example which was translated from router example of Dioxus. More detailed guide will be updated soon.
⚠️ Caution
Nested router is not fully tested. Test and fix is planned for a future release.
Quick Value Animation Example
use *;
Animation Sequences Example
Chain multiple animations together with different configurations:
let scale = use_motion;
// Create a bouncy sequence
let sequence = new
.then
.then
.then;
// Start the sequence
scale.animate_sequence;
// Each step in the sequence can have its own timing, easing, and spring physics configuration. Sequences can also be looped or chained with other animations.
✨ Features
- Cross-Platform Support: Works on web, desktop, and mobile
- Flexible Animation Configuration
- Custom Easing Functions
- Modular Feature Setup
- Simple, Intuitive API
- Page Transitions
🛠 Installation
Add to your Cargo.toml:
[]
= { = "0.3.0", = true, = false }
[]
= ["web"]
= ["dioxus/web", "dioxus-motion/web"]
= ["dioxus/desktop", "dioxus-motion/desktop"]
= ["dioxus/mobile", "dioxus-motion/desktop"]
If you want to use page transiton dependency will look like,
[]
= { = "0.3.0", = true, = false }
[]
= ["web"]
= ["dioxus/web", "dioxus-motion/web", "dioxus-motion/transitions"]
= [
"dioxus/desktop",
"dioxus-motion/desktop",
"dioxus-motion/transitions",
]
= ["dioxus/mobile", "dioxus-motion/desktop", "dioxus-motion/transitions"]
🌐 Platform Support
Choose the right feature for your platform:
web: For web applications using WASMdesktop: For desktop and mobile applicationsdefault: Web support (if no feature specified)
🚀 Quick Start
🔄 Migration Guide (v0.3.0)
- No breaking changes to the existing APIs. Just minor exports might change so just import prelude::* if anything breaks on import
use *;
🔄 Migration Guide (v0.2.0)
Breaking Changes
- Combined
use_value_animationanduse_transform_animationintouse_motion - New animation configuration API
- Updated spring physics parameters
- Changed transform property names
New Animation API
use *;
// Before (v0.1.x)
let mut motion = use_value_animation;
// After (v0.2.x)
let mut value = use_motion;
value.animate_to;
// Before (v0.1.x)
let mut transform = use_transform_animation;
// After (v0.2.x)
let mut transform = use_motion;
transform.animate_to;
If you were using transform.get_style(), that function is removed to make the library more generic so i recommend building something like
let transform = use_motion;
let transform_style = use_memo;
// and using the memo in the component
rsx!
🆕 New Features
Loop Modes
.with_loop
.with_loop
Animation Delays
.with_delay
On Complete
.with_on_complete
🎓 Advanced Guide: Extending Animations
Implementing the Animatable Trait
The Animatable trait allows you to animate any custom type.
Defination of Animatable Trait
Here's how to implement it:
Custom Position Type
Best Practices
- Zero State: Implement zero() as your type's neutral state
- Epsilon: Choose a small value (~0.001) for animation completion checks
- Magnitude: Return the square root of sum of squares for vector types
- Scale: Multiply all components by the factor
- Add/Sub: Implement component-wise addition/subtraction
- Interpolate: Use linear interpolation for smooth transitions
Common Patterns
Circular Values (e.g., angles)
Normalized Values (e.g., colors)
🌈 Supported Easing Functions
Leverages the easer crate, supporting:
- Linear
- Quadratic
- Cubic
- Quartic
- And more!
🤝 Contributing
- Fork the repository
- Create your feature branch
- Commit changes
- Push to the branch
- Create a Pull Request
📄 License
MIT License
🐞 Reporting Issues
Please report issues on the GitHub repository with:
- Detailed description
- Minimal reproducible example
- Platform and feature configuration used
🌟 Motivation
Bringing elegant, performant motion animations to Rust's web and desktop ecosystems with minimal complexity.