From dacf9fc03c6618a0afbf39b2302f60cc835ec711 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Wed, 1 Nov 2023 23:46:01 +0100 Subject: [PATCH] chore: Update i18n example --- Cargo.toml | 2 +- examples/shader.rs | 26 ++++++++++++-------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d76472d74..d723bf01f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,7 +67,7 @@ freya-node-state = { workspace = true } reqwest = { version = "0.11.22", features = ["json"] } serde = "1.0.189" tracing-subscriber = "0.3.17" -dioxus-std = { version = "0.4", features = ["utils", "i18n"] } +dioxus-std = { version = "0.4", features = ["i18n"] } rand = "0.8.5" dioxus-router = { workspace = true } itertools = "0.11.0" diff --git a/examples/shader.rs b/examples/shader.rs index ed113e9a0..b08ef73c1 100644 --- a/examples/shader.rs +++ b/examples/shader.rs @@ -5,13 +5,11 @@ use std::{ sync::{Arc, Mutex}, - time::{Duration, Instant}, + time::Instant, }; -use dioxus_std::utils::channel::{use_channel, use_listen_channel}; -use freya::{common::EventMessage, prelude::*}; +use freya::prelude::*; use skia_safe::{Color, Data, Paint, Rect, RuntimeEffect}; -use tokio::time::sleep; fn main() { launch(app); @@ -36,14 +34,16 @@ const SHADER: &str = " fn app(cx: Scope) -> Element { let platform = use_platform(cx); - let render_channel = use_channel::<()>(cx, 1); - use_listen_channel(cx, &render_channel, move |_| { - to_owned![platform]; - async move { - sleep(Duration::from_millis(25)).await; - platform.send(EventMessage::RequestRerender).unwrap(); - } + cx.use_hook(|| { + let mut ticker = platform.new_ticker(); + + cx.spawn(async move { + loop { + ticker.tick().await; + platform.request_animation_frame(); + } + }); }); let canvas = use_canvas(cx, (), |_| { @@ -51,7 +51,7 @@ fn app(cx: Scope) -> Element { let shader_wrapper = Arc::new(Mutex::new(ShaderWrapper(shader))); let instant = Instant::now(); - to_owned![render_channel, shader_wrapper]; + to_owned![shader_wrapper]; Box::new(move |canvas, _, region| { let shader = shader_wrapper.lock().unwrap(); @@ -83,8 +83,6 @@ fn app(cx: Scope) -> Element { ), &paint, ); - - render_channel.try_send(()).ok(); }) });