Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Dioxus 0.5 support #23

Merged
merged 29 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ members = [
]

[workspace.dependencies]
dioxus-std = { path = "./std"}
dioxus-std = { path = "./std" }
dioxus = { version = "0.5" }
dioxus-web = { version = "0.5" }
dioxus-desktop = { version = "0.5" }
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
- [x] Notifications - (Desktop)
- [x] Color Scheme - (any)
- [x] Utility Hooks
- [x] use_rw - (any)
- [x] use_channel - (any)
- [ ] use_interval (any)
- [x] i18n - (any)
Expand All @@ -49,19 +48,19 @@ use dioxus_std::geolocation::{
init_geolocator, use_geolocation, PowerMode
};

fn app(cx: Scope) -> Element {
let geolocator = init_geolocator(cx, PowerMode::High).unwrap();
let coords = use_geolocation(cx);
fn app() -> Element {
let geolocator = init_geolocator(PowerMode::High).unwrap();
let coords = use_geolocation();

match coords {
Ok(coords) => {
render! { p { format!("Latitude: {} | Longitude: {}", coords.latitude, coords.longitude) } }
rsx!( p { "Latitude: {coords.latitude} | Longitude: {coords.longitude}" } )
}
Err(Error::NotInitialized) => {
render! { p { "Initializing..." }}
rsx!( p { "Initializing..." } )
}
Err(e) => {
render! { p { "An error occurred {e}" }}
rsx!( p { "An error occurred {e}" } )
}
}
}
Expand All @@ -79,7 +78,7 @@ sudo apt-get install xorg-dev
You can add `dioxus-std` to your application by adding it to your dependencies.
```toml
[dependencies]
dioxus-std = { version = "0.4.2", features = [] }
dioxus-std = { version = "0.5", features = [] }
```

## License
Expand Down
4 changes: 2 additions & 2 deletions examples/channel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ edition = "2021"

[dependencies]
dioxus-std = { workspace = true, features = ["utils"]}
dioxus = "0.4"
dioxus-web = "0.4"
dioxus = { workspace = true }
dioxus-web = { workspace = true }

log = "0.4.6"

Expand Down
17 changes: 7 additions & 10 deletions examples/channel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,24 @@ fn main() {
wasm_logger::init(wasm_logger::Config::default());
console_error_panic_hook::set_once();

dioxus_web::launch(app);
launch(app);
}

fn app(cx: Scope) -> Element {
let channel = use_channel::<String>(cx, 5);
fn app() -> Element {
let channel = use_channel::<String>(5);

use_listen_channel(cx, &channel, |message| async {
use_listen_channel(&channel, |message| async {
match message {
Ok(value) => log::info!("Incoming message: {value}"),
Err(err) => log::info!("Error: {err:?}"),
}
});

let send = |_: MouseEvent| {
to_owned![channel];
async move {
channel.send("Hello").await.ok();
}
let send = move |_: MouseEvent| async move {
channel.send("Hello").await.ok();
};

render!(
rsx!(
button {
onclick: send,
"Send hello"
Expand Down
4 changes: 2 additions & 2 deletions examples/clipboard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ edition = "2021"

[dependencies]
dioxus-std = { workspace = true, features = ["clipboard"] }
dioxus = "0.4"
dioxus-desktop = "0.4"
dioxus = { workspace = true }
dioxus-desktop = { workspace = true }
19 changes: 8 additions & 11 deletions examples/clipboard/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@ fn main() {
dioxus_desktop::launch(app);
}

fn app(cx: Scope) -> Element {
let clipboard = use_clipboard(cx);
let text = use_state(cx, String::new);
fn app() -> Element {
let mut clipboard = use_clipboard();
let mut text = use_signal(String::new);

let oninput = |e: FormEvent| {
let oninput = move |e: FormEvent| {
text.set(e.data.value.clone());
};

let oncopy = {
to_owned![clipboard];
move |_| match clipboard.set(text.get().clone()) {
Ok(_) => println!("Copied to clipboard: {}", text.get()),
Err(err) => println!("Error on copy: {err:?}"),
}
let oncopy = move |_| match clipboard.set(text.read().clone()) {
Ok(_) => println!("Copied to clipboard: {}", text.read()),
Err(err) => println!("Error on copy: {err:?}"),
};

let onpaste = move |_| match clipboard.get() {
Expand All @@ -29,7 +26,7 @@ fn app(cx: Scope) -> Element {
Err(err) => println!("Error on paste: {err:?}"),
};

render!(
rsx!(
input {
oninput: oninput,
value: "{text}"
Expand Down
4 changes: 2 additions & 2 deletions examples/color_scheme/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ edition = "2021"

[dependencies]
dioxus-std = { workspace = true, features = ["color_scheme"] }
dioxus = "0.4"
dioxus-web = "0.4"
dioxus = { workspace = true }
dioxus-web = { workspace = true }

log = "0.4.6"

Expand Down
6 changes: 3 additions & 3 deletions examples/color_scheme/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ fn main() {
dioxus_web::launch(app);
}

fn app(cx: Scope) -> Element {
let color_scheme = use_preferred_color_scheme(cx);
fn app() -> Element {
let color_scheme = use_preferred_color_scheme();

render!(
rsx!(
div {
style: "text-align: center;",
h1 { "🌗 Dioxus 🚀" }
Expand Down
6 changes: 3 additions & 3 deletions examples/geolocation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ edition = "2021"

[dependencies]
dioxus-std = { workspace = true, features = ["geolocation"] }
dioxus = "0.4"
dioxus-desktop = "0.4"
#dioxus-web = "0.4"
dioxus = { workspace = true }
dioxus-desktop ={ workspace = true }
# dioxus-web ={ workspace = true }
18 changes: 8 additions & 10 deletions examples/geolocation/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ fn main() {
//dioxus_web::launch(app);
}

fn app(cx: Scope) -> Element {
let geolocator = init_geolocator(cx, PowerMode::High).unwrap();
let initial_coords = use_future(cx, (), |_| async move {
geolocator.get_coordinates().await.unwrap()
});
let latest_coords = use_geolocation(cx);
fn app() -> Element {
let geolocator = init_geolocator(PowerMode::High).unwrap();
let initial_coords = use_future(|_| async move { geolocator.get_coordinates().await.unwrap() });
let latest_coords = use_geolocation();

let latest_coords = match latest_coords {
Ok(v) => v,
Err(e) => {
let e = format!("Initializing: {:?}", e);
return cx.render(rsx!(p { "{e}" }));
return rsx!(p { "{e}" });
}
};

Expand All @@ -26,15 +24,15 @@ fn app(cx: Scope) -> Element {

let initial_coords = initial_coords.value();

cx.render(rsx! (
rsx!(
div {
style: "text-align: center;",
h1 { "🗺️ Dioxus Geolocation Example 🛰️" }
h3 { "Your initial location is:"}

p {
if let Some(coords) = initial_coords {
format!("Latitude: {} | Longitude: {}", coords.latitude, coords.longitude)
format!("Latitude: {} | Longitude: {}", coords.latitude, coords.longitude)
} else {
"Loading...".to_string()
}
Expand All @@ -51,5 +49,5 @@ fn app(cx: Scope) -> Element {
// src: "https://www.google.com/maps/embed/v1/view?key={key}&center={latest_coords.latitude},{latest_coords.longitude}&zoom=16",
//}
}
))
)
}
4 changes: 2 additions & 2 deletions examples/i18n/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ edition = "2021"

[dependencies]
dioxus-std = { workspace = true, features = ["i18n"] }
dioxus = "0.4"
dioxus-web = "0.4"
dioxus = { workspace = true }
dioxus-web = { workspace = true }

log = "0.4.6"

Expand Down
27 changes: 11 additions & 16 deletions examples/i18n/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ static EN_US: &str = include_str!("./en-US.json");
static ES_ES: &str = include_str!("./es-ES.json");

#[allow(non_snake_case)]
fn Body(cx: Scope) -> Element {
let i18 = use_i18(cx);
fn Body() -> Element {
let i18 = use_i18();

let change_to_english = move |_| i18.set_language("en-US".parse().unwrap());
let change_to_spanish = move |_| i18.set_language("es-ES".parse().unwrap());

render!(
rsx!(
button {
onclick: change_to_english,
label {
Expand All @@ -39,17 +39,12 @@ fn Body(cx: Scope) -> Element {
)
}

fn app(cx: Scope) -> Element {
use_init_i18n(
cx,
"en-US".parse().unwrap(),
"en-US".parse().unwrap(),
|| {
let en_us = Language::from_str(EN_US).unwrap();
let es_es = Language::from_str(ES_ES).unwrap();
vec![en_us, es_es]
},
);

render!(Body {})
fn app() -> Element {
use_init_i18n("en-US".parse().unwrap(), "en-US".parse().unwrap(), || {
let en_us = Language::from_str(EN_US).unwrap();
let es_es = Language::from_str(ES_ES).unwrap();
vec![en_us, es_es]
});

rsx!(Body {})
}
12 changes: 4 additions & 8 deletions std/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dioxus-std"
version = "0.4.2"
version = "0.5.0"
authors = ["Jonathan Kelley", "Dioxus Labs", "ealmloff", "DogeDark", "marc2332"]
edition = "2021"
description = "Platform agnostic library for supercharging your productivity with Dioxus"
Expand All @@ -18,11 +18,10 @@ categories = ["multimedia", "os", "wasm"]

[features]
utils = ["dep:async-broadcast", "uuid/v4"]
clipboard = ["dep:dioxus", "dep:copypasta"]
notifications = ["dep:dioxus", "dep:notify-rust"]
clipboard = ["dep:copypasta"]
notifications = ["dep:notify-rust"]
geolocation = [
# Shared
"dep:dioxus",
"dep:futures",
"dep:futures-util",

Expand All @@ -37,9 +36,6 @@ geolocation = [
"dep:wasm-bindgen",
]
color_scheme = [
# Shared
"dep:dioxus",

# Wasm
"web-sys/Window",
"web-sys/MediaQueryList",
Expand All @@ -65,8 +61,8 @@ desktop-testing = ["clipboard", "notifications", "geolocation", "utils", "i18n"]
# # # # # # # # # # # # # # #

[dependencies]
dioxus = { workspace = true }
cfg-if = "1.0.0"
dioxus = { version = "0.4", optional = true }

# Used by: clipboard
copypasta = { version = "0.8.2", optional = true }
Expand Down
Loading
Loading