-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restyle when style attribute is mutated
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters