Dioxus Motion 🚀
A lightweight, cross-platform animation library for Dioxus, designed to bring smooth, flexible animations to your Rust web, desktop, and mobile applications.
⚠️ Important Note
This repository follows Dioxus's main branch for the latest features and improvements. For production use, we recommend using the stable version from crates.io instead of directly depending on the repository.
# Recommended: Stable version from crates.io
= "0.3.1"
# Development version: Follows Dioxus main branch
= { = "https://github.com/wheregmis/dioxus-motion.git", = "main" }
🎯 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.
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
- 🔧 Simplified Animatable Trait: Uses standard Rust operators (
+,-,*) instead of custom methods - 🌍 Cross-Platform Support: Works on web, desktop, and mobile
- ⚙️ Flexible Animation Configuration: Spring physics and tween animations
- 📊 Custom Easing Functions: Built-in and custom easing support
- 🧩 Modular Feature Setup: Choose only what you need
- 💡 Simple, Intuitive API: Easy to learn and use
- 🎬 Page Transitions: Smooth route transitions with the
transitionsfeature
🛠 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
🎨 Creating Custom Animatable Types
The simplified Animatable trait makes it easy to create custom animatable types:
use *;
// Point3D automatically implements Send + 'static since all fields are Send + 'static
// Implement standard Rust operator traits
// Implement Animatable with just two methods!
// Now you can animate 3D points!
let mut position = use_motion;
position.animate_to;
Previous vs. New Trait Complexity:
- Before: 7 required methods (
zero,epsilon,magnitude,scale,add,sub,interpolate) - After: 2 required methods (
interpolate,magnitude) + standard Rust operators - Result: ~70% less boilerplate, more idiomatic Rust code!
🔄 Migration Guide (v0.3.0)
Breaking Changes
use_motion<T>now requiresT: Send + 'static: Theuse_motion<T>function now requires types to implementSend + 'staticin addition toAnimatable. This enables better thread safety and resource management for animations.
Migration Steps
- Most built-in types (
f32,Transform,Color) already satisfy these bounds - For custom types, ensure they implement
Send + 'static:- Types with non-Send fields (like
Rc<T>) will need to be refactored - Use
Arc<T>instead ofRc<T>for shared ownership in animatable types
- Types with non-Send fields (like
- Minor exports might change so just import
prelude::*if anything breaks on import
use *;
// ✅ This works - f32 is Send + 'static
let motion = use_motion;
// ✅ This works - custom type with Send + 'static
// Send + 'static automatically derived
let point_motion = use_motion;
// ❌ This won't compile - Rc<T> is not Send
// let bad_motion = use_motion(std::rc::Rc::new(0.0f32));
// ✅ Use Arc<T> instead for shared ownership
// Note: The type inside Arc must implement Animatable
let shared_motion = use_motion;
// ✅ Alternative: Use Arc to share the motion itself (not the value)
let shared_motion_handle = new;
// Now you can clone the Arc and share the motion across components
let motion_clone = shared_motion_handle.clone;
🔄 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.
Definition of Animatable Trait
Here's how to implement it:
Custom Position Type
// Implement standard Rust operator traits
// Implement Animatable with just two methods!
Best Practices
- Default State: Implement
Defaulttrait for your type's neutral state - Operator Traits: Implement
Add,Sub, andMul<f32>using standard Rust operators - Magnitude: Return the square root of sum of squares for vector types
- Interpolate: Use linear interpolation for smooth transitions
- Epsilon: Uses default 0.01, or override with
with_epsilon()for custom precision
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.