Skip to content

Commit

Permalink
Restyle when style attribute is mutated
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Jan 6, 2025
1 parent e5c763b commit 54a7956
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
38 changes: 38 additions & 0 deletions examples/restyle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use dioxus::prelude::*;
use tokio::time::{sleep, Duration};

fn main() {
// Turn on the runtime and enter it
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();
let _guard = rt.enter();

dioxus_native::launch(app);
}

fn app() -> Element {
let mut count = use_signal(|| 0);
let mut running = use_signal(|| true);
// `use_future` will spawn an infinitely running future that can be started and stopped
use_future(move || async move {
loop {
if running() {
count += 1;
}
sleep(Duration::from_millis(40)).await;
}
});
rsx! {
div {
h1 { "Current count: {count}" }
p {
style: "font-size: {count}px",
"Animate Font Size"
}
button { onclick: move |_| running.toggle(), "Start/Stop the count"}
button { onclick: move |_| count.set(0), "Reset the count" }
}
}
}
4 changes: 4 additions & 0 deletions packages/dioxus-native/src/mutation_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ impl WriteMutations for MutationWriter<'_> {
});
}
}

if name == "style" {
element.flush_style_attribute(&self.doc.guard);
}
}

if let AttributeValue::None = value {
Expand Down

0 comments on commit 54a7956

Please sign in to comment.