Merge branch 'master' into master

This commit is contained in:
Jonathan Kelley authored and GitHub committed 2023-07-14 15:36:28 -07:00
commit af49cb4ec6
313 files changed
+23988 -2334

No files matched your search

+1 -1
View File
@@ -40,7 +40,7 @@ cargo run --example hello_world
[all_css](./all_css.rs) - You can specify any CSS attribute
[tailwind](./tailwind.rs) - You can use a library for styling
[tailwind](./tailwind/) - You can use a library for styling
## Input Handling
+10
View File
@@ -0,0 +1,10 @@
# Rust
target/
**/*.rs.bk
# tauri-mobile
.cargo/
/gen
# macOS
.DS_Store
+54
View File
@@ -0,0 +1,54 @@
[package]
name = "mobile-demo"
version = "0.1.0"
authors = ["Jonathan Kelley <jkelleyrtp@gmail.com>"]
edition = "2018"
[lib]
crate-type = ["staticlib", "cdylib", "rlib"]
[[bin]]
name = "mobile-demo-desktop"
path = "gen/bin/desktop.rs"
[package.metadata.cargo-android]
app-activity-name = "com.example.mobile_demo.MainActivity"
app-dependencies = [
"androidx.webkit:webkit:1.6.1",
"androidx.appcompat:appcompat:1.6.1",
"com.google.android.material:material:1.8.0",
]
project-dependencies = ["org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"]
app-plugins = ["org.jetbrains.kotlin.android"]
app-permissions = ["android.permission.INTERNET"]
app-theme-parent = "Theme.MaterialComponents.DayNight.DarkActionBar"
vulkan-validation = false
[package.metadata.cargo-android.env-vars]
WRY_ANDROID_PACKAGE = "com.example.mobile_demo"
WRY_ANDROID_LIBRARY = "mobile_demo"
WRY_ANDROID_KOTLIN_FILES_OUT_DIR = "<android-project-dir>/app/src/main/kotlin/com/example/mobile_demo"
[package.metadata.cargo-apple.ios]
frameworks = ["WebKit"]
[dependencies]
anyhow = "1.0.56"
log = "0.4.11"
wry = "0.28.0"
dioxus = { path = "../../packages/dioxus" }
dioxus-desktop = { path = "../../packages/desktop", features = [
"tokio_runtime",
], default-features = false }
[target.'cfg(target_os = "android")'.dependencies]
android_logger = "0.9.0"
jni = "0.19.0"
paste = "1.0"
[target.'cfg(not(target_os = "android"))'.dependencies]
env_logger = "0.9.0"
[target.'cfg(target_os = "ios")'.dependencies]
core-foundation = "0.9.3"
+46
View File
@@ -0,0 +1,46 @@
# Dioxus Mobile demo
## How this project was generated
Right now, Dioxus supports mobile targets including iOS and Android. However, our tooling is not mature enough to include the build commands directly.
This project was generated using [tauri-mobile](https://github.com/tauri-apps/tauri-mobile). We have yet to integrate this generation into the Dioxus-CLI. The open issue for this is [#1157](https://github.com/DioxusLabs/dioxus/issues/1157).
## Running on iOS
First, you'll want to make sure you have the appropriate iOS targets installed.
The two targets you'll use the most are:
- `aarch64-apple-ios-sim`
- `aarch64-apple-ios`
These can be added using
- `rustup target add aarch64-apple-ios-sim`
- `rustup target add aarch64-apple-ios`
From there, you'll want to get a build of the crate using whichever platform you're targeting (simulator or actual hardware). For now, we'll just stick with the simulator:
- `cargo build --target aarch64-apple-ios-sim`
Then, you'll want to open XCode. This might take awhile if you've never opened XCode before. The command you want to use is:
- `cargo apple open`
This will open XCode with this particular project.
From there, just click the "play" button with the right target and the app should be running!
![ios_demo](ios_demo.png)
Note that clicking play doesn't cause a new build, so you'll need to keep rebuilding the app between changes. The tooling here is very young, so please be patient. If you want to contribute to make things easier, please do! We'll be happy to help.
## Running on Android
Again, we want to make sure we have the right targets installed.
The common targets here are
- aarch64-linux-android
- armv7-linux-androideabi
- i686-linux-android
- x86_64-linux-android
+8
View File
@@ -0,0 +1,8 @@
[app]
name = "mobile-demo"
stylized-name = "Mobile Demo"
domain = "example.com"
template-pack = "wry"
[apple]
development-team = "34U4FG9TJ8"
+12
View File
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Dioxus app</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<!-- CUSTOM HEAD -->
</head>
<body>
<div id="main"></div>
<!-- MODULE LOADER -->
</body>
</html>
+86
View File
@@ -0,0 +1,86 @@
use anyhow::Result;
use dioxus::prelude::*;
use dioxus_desktop::Config;
#[cfg(target_os = "android")]
use wry::android_binding;
#[cfg(target_os = "android")]
fn init_logging() {
android_logger::init_once(
android_logger::Config::default()
.with_min_level(log::Level::Trace)
.with_tag("mobile-demo"),
);
}
#[cfg(not(target_os = "android"))]
fn init_logging() {
env_logger::init();
}
#[cfg(any(target_os = "android", target_os = "ios"))]
fn stop_unwind<F: FnOnce() -> T, T>(f: F) -> T {
match std::panic::catch_unwind(std::panic::AssertUnwindSafe(f)) {
Ok(t) => t,
Err(err) => {
eprintln!("attempt to unwind out of `rust` with err: {:?}", err);
std::process::abort()
}
}
}
#[cfg(any(target_os = "android", target_os = "ios"))]
fn _start_app() {
stop_unwind(|| main().unwrap());
}
#[no_mangle]
#[inline(never)]
#[cfg(any(target_os = "android", target_os = "ios"))]
pub extern "C" fn start_app() {
#[cfg(target_os = "android")]
android_binding!(com_example, mobile_demo, _start_app);
#[cfg(target_os = "ios")]
_start_app()
}
pub fn main() -> Result<()> {
init_logging();
// Right now we're going through dioxus-desktop but we'd like to go through dioxus-mobile
// That will seed the index.html with some fixes that prevent the page from scrolling/zooming etc
dioxus_desktop::launch_cfg(
app,
// Note that we have to disable the viewport goofiness of the browser.
// Dioxus_mobile should do this for us
Config::default().with_custom_index(include_str!("index.html").to_string()),
);
Ok(())
}
fn app(cx: Scope) -> Element {
let items = cx.use_hook(|| vec![1, 2, 3]);
log::debug!("Hello from the app");
render! {
div {
h1 { "Hello, Mobile"}
div { margin_left: "auto", margin_right: "auto", width: "200px", padding: "10px", border: "1px solid black",
button {
onclick: move|_| {
println!("Clicked!");
items.push(items.len());
cx.needs_update_any(ScopeId(0));
println!("Requested update");
},
"Add item"
}
for item in items.iter() {
div { "- {item}" }
}
}
}
}
}
+77
View File
@@ -0,0 +1,77 @@
#![allow(non_snake_case)]
use std::collections::HashMap;
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(App);
}
#[derive(Default)]
struct CoolData {
data: HashMap<usize, String>,
}
impl CoolData {
pub fn new(data: HashMap<usize, String>) -> Self {
Self { data }
}
pub fn view(&self, id: &usize) -> Option<&String> {
self.data.get(id)
}
pub fn set(&mut self, id: usize, data: String) {
self.data.insert(id, data);
}
}
#[rustfmt::skip]
pub fn App(cx: Scope) -> Element {
use_shared_state_provider(cx, || CoolData::new(HashMap::from([
(0, "Hello, World!".to_string()),
(1, "Dioxus is amazing!".to_string())
])));
render!(
DataEditor {
id: 0
}
DataEditor {
id: 1
}
DataView {
id: 0
}
DataView {
id: 1
}
)
}
#[inline_props]
fn DataEditor(cx: Scope, id: usize) -> Element {
let cool_data = use_shared_state::<CoolData>(cx).unwrap().read();
let my_data = &cool_data.view(&id).unwrap();
render!(p {
"{my_data}"
})
}
#[inline_props]
fn DataView(cx: Scope, id: usize) -> Element {
let cool_data = use_shared_state::<CoolData>(cx).unwrap();
let oninput = |e: FormEvent| cool_data.write().set(*id, e.value.clone());
let cool_data = cool_data.read();
let my_data = &cool_data.view(&id).unwrap();
render!(input {
oninput: oninput,
value: "{my_data}"
})
}
+2 -2
View File
@@ -1,5 +1,4 @@
use dioxus::prelude::*;
use dioxus_desktop::tao::keyboard::ModifiersState;
use dioxus_desktop::use_global_shortcut;
fn main() {
@@ -8,7 +7,8 @@ fn main() {
fn app(cx: Scope) -> Element {
let toggled = use_state(cx, || false);
use_global_shortcut(cx, KeyCode::S, ModifiersState::CONTROL, {
use_global_shortcut(cx, "ctrl+s", {
to_owned![toggled];
move || toggled.modify(|t| !*t)
});
+1 -4
View File
@@ -1,5 +1,4 @@
use dioxus::prelude::*;
use dioxus_signals::{use_init_signal_rt, use_signal};
use std::time::Duration;
fn main() {
@@ -7,9 +6,7 @@ fn main() {
}
fn app(cx: Scope) -> Element {
use_init_signal_rt(cx);
let mut count = use_signal(cx, || 0);
let mut count = dioxus_signals::use_signal(cx, || 0);
use_future!(cx, || async move {
loop {
+4 -1
View File
@@ -2,9 +2,12 @@ use dioxus::prelude::*;
use dioxus_desktop::tao::event::WindowEvent;
use dioxus_desktop::use_wry_event_handler;
use dioxus_desktop::wry::application::event::Event as WryEvent;
use dioxus_desktop::{Config, WindowCloseBehaviour};
fn main() {
dioxus_desktop::launch(app);
let cfg = Config::new().with_close_behaviour(WindowCloseBehaviour::CloseWindow);
dioxus_desktop::launch_cfg(app, cfg);
}
fn app(cx: Scope) -> Element {