#How to access window size?

1 messages · Page 1 of 1 (latest)

shy briar
shy briar
#

I see Scope was deprecated in 0.4 and to use provide_context hook instead. Hopefully I can answer my own question after finding that.

shy briar
tulip flume
#

This is great but is WASM/Web only. I made an eval() that used a resize watcher in JS and then used a use_future() in dioxus that read the result and wrote to a global signal.

#

It ended up looking like:

    // Start screen size watcher
    use_future(move || async move {
        let mut eval = eval(
            r"
            function resize() {
                dioxus.send([window.innerWidth, window.innerHeight]);
            }
            window.addEventListener('resize', resize);
            dioxus.send([window.innerWidth, window.innerHeight]);
        ",
        );
        loop {
            let response = eval.recv().await.unwrap();
            let dims: (f64, f64) = serde_json::from_value(response).unwrap();
            *WINDOW_DIMS.write() = Point2D::new(dims.0, dims.1);
        }
    });