feat(ui-dioxus): use dioxus-motion for Blitz-compatible pulse animation
This commit is contained in:
parent
c9f8679744
commit
67ab77ebf4
3 changed files with 3861 additions and 1240 deletions
5046
ui-dioxus/Cargo.lock
generated
5046
ui-dioxus/Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -15,4 +15,5 @@ serde = { version = "1", features = ["derive"] }
|
|||
serde_json = "1"
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
dioxus-motion = { version = "0.3", default-features = false, features = ["desktop"] }
|
||||
log = "0.4"
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
/// PulsingDot — GPU-friendly animated status indicator for Blitz renderer.
|
||||
/// PulsingDot — Blitz-compatible animated status indicator using dioxus-motion.
|
||||
///
|
||||
/// Pure OS-thread animation — no async runtime dependency.
|
||||
/// OS thread updates AtomicU32 + calls schedule_update() to trigger re-render.
|
||||
/// schedule_update() returns Arc<dyn Fn() + Send + Sync> — safe from any thread.
|
||||
/// Uses dioxus-motion's Tween with LoopMode::Alternate for infinite ping-pong.
|
||||
/// Avoids CSS @keyframes entirely — no Blitz full-scene repaint loop.
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use dioxus_motion::prelude::*;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub enum DotState {
|
||||
|
|
@ -21,35 +18,18 @@ pub enum DotState {
|
|||
#[component]
|
||||
pub fn PulsingDot(state: DotState, size: Option<String>) -> Element {
|
||||
let should_pulse = matches!(state, DotState::Running | DotState::Stalled);
|
||||
let mut opacity = use_motion(1.0f32);
|
||||
|
||||
// Shared atomic for cross-thread opacity (f32 as u32 bits)
|
||||
let atomic_opacity = use_hook(|| Arc::new(AtomicU32::new(f32::to_bits(1.0))));
|
||||
|
||||
// Infinite ping-pong tween: 1.0 → 0.4 → 1.0 → ...
|
||||
if should_pulse {
|
||||
let ao = atomic_opacity.clone();
|
||||
// schedule_update returns Arc<dyn Fn() + Send + Sync> — works from OS threads
|
||||
let updater = use_hook(|| dioxus::dioxus_core::schedule_update());
|
||||
|
||||
use_hook(move || {
|
||||
std::thread::spawn(move || {
|
||||
let steps = 8u32;
|
||||
let step_ms = 125u64;
|
||||
let mut going_down = true;
|
||||
loop {
|
||||
for i in 0..steps {
|
||||
let t = i as f32 / (steps - 1) as f32;
|
||||
let val = if going_down {
|
||||
1.0 - (t * 0.6)
|
||||
} else {
|
||||
0.4 + (t * 0.6)
|
||||
};
|
||||
ao.store(f32::to_bits(val), Ordering::Relaxed);
|
||||
updater(); // Trigger re-render from OS thread
|
||||
std::thread::sleep(Duration::from_millis(step_ms));
|
||||
}
|
||||
going_down = !going_down;
|
||||
}
|
||||
});
|
||||
use_effect(move || {
|
||||
opacity.animate_to(
|
||||
0.4,
|
||||
AnimationConfig::new(AnimationMode::Tween(
|
||||
Tween::new(Duration::from_millis(1000))
|
||||
))
|
||||
.with_loop(LoopMode::Alternate),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -62,11 +42,7 @@ pub fn PulsingDot(state: DotState, size: Option<String>) -> Element {
|
|||
};
|
||||
|
||||
let sz = size.unwrap_or_else(|| "8px".to_string());
|
||||
let op = if should_pulse {
|
||||
f32::from_bits(atomic_opacity.load(Ordering::Relaxed))
|
||||
} else {
|
||||
1.0
|
||||
};
|
||||
let op = if should_pulse { opacity.get_value() } else { 1.0 };
|
||||
|
||||
rsx! {
|
||||
span {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue