mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-09-20 06:11:57 +00:00
Android build working too
This commit is contained in:
parent
5506c568c0
commit
ea3b199eb2
10 changed files with 40 additions and 125 deletions
|
@ -40,7 +40,7 @@ members = [
|
|||
"playwrite-tests/web",
|
||||
"playwrite-tests/fullstack",
|
||||
]
|
||||
exclude = ["examples/ios_demo"]
|
||||
exclude = ["examples/mobile_demo"]
|
||||
|
||||
# dependencies that are shared across packages
|
||||
[workspace.dependencies]
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.2 MiB |
|
@ -1,12 +0,0 @@
|
|||
<!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>
|
|
@ -1,84 +0,0 @@
|
|||
use anyhow::Result;
|
||||
use dioxus::prelude::*;
|
||||
#[cfg(target_os = "android")]
|
||||
use wry::android_binding;
|
||||
|
||||
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 = use_state(cx, || vec![1, 2, 3]);
|
||||
|
||||
render! {
|
||||
div {
|
||||
h1 { "Hello, Mobile"}
|
||||
div { margin_left: "auto", margin_right: "auto", width: "200px", padding: "10px", border: "1px solid black",
|
||||
button {
|
||||
onclick: move|_| {
|
||||
let mut _items = items.make_mut();
|
||||
let len = _items.len() + 1;
|
||||
_items.push(len);
|
||||
},
|
||||
"Add item"
|
||||
}
|
||||
for item in items.iter() {
|
||||
div { "- {item}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
fn init_logging() {
|
||||
android_logger::init_once(
|
||||
android_logger::Config::default()
|
||||
.with_min_level(log::Level::Trace)
|
||||
.with_tag("rustnl-ios"),
|
||||
);
|
||||
}
|
||||
|
||||
#[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() {
|
||||
main().unwrap();
|
||||
}
|
||||
|
||||
use dioxus_desktop::Config;
|
||||
|
||||
#[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, rustnl_ios, _start_app);
|
||||
#[cfg(target_os = "ios")]
|
||||
_start_app()
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "rustnl-ios"
|
||||
name = "mobile-demo"
|
||||
version = "0.1.0"
|
||||
authors = ["Jonathan Kelley <jkelleyrtp@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
@ -8,11 +8,11 @@ edition = "2018"
|
|||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[[bin]]
|
||||
name = "rustnl-ios-desktop"
|
||||
name = "mobile-demo-desktop"
|
||||
path = "gen/bin/desktop.rs"
|
||||
|
||||
[package.metadata.cargo-android]
|
||||
app-activity-name = "com.example.rustnl_ios.MainActivity"
|
||||
app-activity-name = "com.example.mobile_demo.MainActivity"
|
||||
app-dependencies = [
|
||||
"androidx.webkit:webkit:1.6.1",
|
||||
"androidx.appcompat:appcompat:1.6.1",
|
||||
|
@ -25,9 +25,9 @@ app-theme-parent = "Theme.MaterialComponents.DayNight.DarkActionBar"
|
|||
vulkan-validation = false
|
||||
|
||||
[package.metadata.cargo-android.env-vars]
|
||||
WRY_ANDROID_PACKAGE = "com.example.rustnl_ios"
|
||||
WRY_ANDROID_LIBRARY = "rustnl_ios"
|
||||
WRY_ANDROID_KOTLIN_FILES_OUT_DIR = "<android-project-dir>/app/src/main/kotlin/com/example/rustnl_ios"
|
||||
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"]
|
||||
|
@ -35,12 +35,12 @@ frameworks = ["WebKit"]
|
|||
[dependencies]
|
||||
anyhow = "1.0.56"
|
||||
log = "0.4.11"
|
||||
im-rc = "15.1.0"
|
||||
wry = "0.28.0"
|
||||
dioxus = { path = "../../packages/dioxus" }
|
||||
dioxus-desktop = { path = "../../packages/desktop", default-features = false, features = [
|
||||
dioxus-desktop = { path = "../../packages/desktop", features = [
|
||||
"tokio_runtime",
|
||||
] }
|
||||
wry = { version = "0.28.0" }
|
||||
], default-features = false }
|
||||
|
||||
|
||||
[target.'cfg(target_os = "android")'.dependencies]
|
||||
android_logger = "0.9.0"
|
|
@ -43,3 +43,4 @@ The common targets here are
|
|||
- armv7-linux-androideabi
|
||||
- i686-linux-android
|
||||
- x86_64-linux-android
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
[app]
|
||||
name = "rustnl-ios"
|
||||
stylized-name = "Rustnl Ios"
|
||||
name = "mobile-demo"
|
||||
stylized-name = "Mobile Demo"
|
||||
domain = "example.com"
|
||||
template-pack = "wry"
|
||||
|
|
@ -1,13 +1,22 @@
|
|||
use anyhow::Result;
|
||||
#[cfg(target_os = "android")]
|
||||
use wry::android_binding;
|
||||
use wry::{
|
||||
application::{
|
||||
event::{Event, StartCause, WindowEvent},
|
||||
event_loop::{ControlFlow, EventLoop, EventLoopWindowTarget},
|
||||
window::WindowBuilder,
|
||||
},
|
||||
http::Response,
|
||||
webview::{WebView, WebViewBuilder},
|
||||
};
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
fn init_logging() {
|
||||
android_logger::init_once(
|
||||
android_logger::Config::default()
|
||||
.with_min_level(log::Level::Trace)
|
||||
.with_tag("android-taurio"),
|
||||
.with_tag("mobile-demo"),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -37,7 +46,7 @@ fn _start_app() {
|
|||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
pub extern "C" fn start_app() {
|
||||
#[cfg(target_os = "android")]
|
||||
android_binding!(com_example, android_taurio, _start_app);
|
||||
android_binding!(com_example, mobile_demo, _start_app);
|
||||
#[cfg(target_os = "ios")]
|
||||
_start_app()
|
||||
}
|
||||
|
@ -46,11 +55,12 @@ pub fn main() -> Result<()> {
|
|||
init_logging();
|
||||
|
||||
use dioxus::prelude::*;
|
||||
fn app(cx: Scope) -> Element {
|
||||
render!("hello dioxus")
|
||||
}
|
||||
|
||||
dioxus_desktop::launch(app);
|
||||
dioxus_desktop::launch(|cx| {
|
||||
cx.render(rsx! {
|
||||
"hello world!"
|
||||
})
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -123,16 +123,16 @@ pub fn launch_with_props<P: 'static>(root: Component<P>, props: P, cfg: Config)
|
|||
let proxy = event_loop.create_proxy();
|
||||
|
||||
// Intialize hot reloading if it is enabled
|
||||
// #[cfg(all(feature = "hot-reload", debug_assertions))]
|
||||
// dioxus_hot_reload::connect({
|
||||
// let proxy = proxy.clone();
|
||||
// move |template| {
|
||||
// let _ = proxy.send_event(UserWindowEvent(
|
||||
// EventData::HotReloadEvent(template),
|
||||
// unsafe { WindowId::dummy() },
|
||||
// ));
|
||||
// }
|
||||
// });
|
||||
#[cfg(all(feature = "hot-reload", debug_assertions))]
|
||||
dioxus_hot_reload::connect({
|
||||
let proxy = proxy.clone();
|
||||
move |template| {
|
||||
let _ = proxy.send_event(UserWindowEvent(
|
||||
EventData::HotReloadEvent(template),
|
||||
unsafe { WindowId::dummy() },
|
||||
));
|
||||
}
|
||||
});
|
||||
|
||||
// We start the tokio runtime *on this thread*
|
||||
// Any future we poll later will use this runtime to spawn tasks and for IO
|
||||
|
|
Loading…
Reference in a new issue