瀏覽代碼

Android build working too

Jonathan Kelley 2 年之前
父節點
當前提交
ea3b199eb2

+ 1 - 1
Cargo.toml

@@ -40,7 +40,7 @@ members = [
     "playwrite-tests/web",
     "playwrite-tests/web",
     "playwrite-tests/fullstack",
     "playwrite-tests/fullstack",
 ]
 ]
-exclude = ["examples/ios_demo"]
+exclude = ["examples/mobile_demo"]
 
 
 # dependencies that are shared across packages
 # dependencies that are shared across packages
 [workspace.dependencies]
 [workspace.dependencies]

二進制
examples/ios_demo/ios_demo.png


+ 0 - 12
examples/ios_demo/src/index.html

@@ -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>

+ 0 - 84
examples/ios_demo/src/lib_old.rs

@@ -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()
-}

+ 0 - 0
examples/ios_demo/.gitignore → examples/mobile_demo/.gitignore


+ 10 - 10
examples/ios_demo/Cargo.toml → examples/mobile_demo/Cargo.toml

@@ -1,5 +1,5 @@
 [package]
 [package]
-name = "rustnl-ios"
+name = "mobile-demo"
 version = "0.1.0"
 version = "0.1.0"
 authors = ["Jonathan Kelley <jkelleyrtp@gmail.com>"]
 authors = ["Jonathan Kelley <jkelleyrtp@gmail.com>"]
 edition = "2018"
 edition = "2018"
@@ -8,11 +8,11 @@ edition = "2018"
 crate-type = ["staticlib", "cdylib", "rlib"]
 crate-type = ["staticlib", "cdylib", "rlib"]
 
 
 [[bin]]
 [[bin]]
-name = "rustnl-ios-desktop"
+name = "mobile-demo-desktop"
 path = "gen/bin/desktop.rs"
 path = "gen/bin/desktop.rs"
 
 
 [package.metadata.cargo-android]
 [package.metadata.cargo-android]
-app-activity-name = "com.example.rustnl_ios.MainActivity"
+app-activity-name = "com.example.mobile_demo.MainActivity"
 app-dependencies = [
 app-dependencies = [
     "androidx.webkit:webkit:1.6.1",
     "androidx.webkit:webkit:1.6.1",
     "androidx.appcompat:appcompat:1.6.1",
     "androidx.appcompat:appcompat:1.6.1",
@@ -25,9 +25,9 @@ app-theme-parent = "Theme.MaterialComponents.DayNight.DarkActionBar"
 vulkan-validation = false
 vulkan-validation = false
 
 
 [package.metadata.cargo-android.env-vars]
 [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]
 [package.metadata.cargo-apple.ios]
 frameworks = ["WebKit"]
 frameworks = ["WebKit"]
@@ -35,12 +35,12 @@ frameworks = ["WebKit"]
 [dependencies]
 [dependencies]
 anyhow = "1.0.56"
 anyhow = "1.0.56"
 log = "0.4.11"
 log = "0.4.11"
-im-rc = "15.1.0"
+wry = "0.28.0"
 dioxus = { path = "../../packages/dioxus" }
 dioxus = { path = "../../packages/dioxus" }
-dioxus-desktop = { path = "../../packages/desktop", default-features = false, features = [
+dioxus-desktop = { path = "../../packages/desktop", features = [
     "tokio_runtime",
     "tokio_runtime",
-] }
-wry = { version = "0.28.0" }
+], default-features = false }
+
 
 
 [target.'cfg(target_os = "android")'.dependencies]
 [target.'cfg(target_os = "android")'.dependencies]
 android_logger = "0.9.0"
 android_logger = "0.9.0"

+ 1 - 0
examples/ios_demo/README.md → examples/mobile_demo/README.md

@@ -43,3 +43,4 @@ The common targets here are
 - armv7-linux-androideabi
 - armv7-linux-androideabi
 - i686-linux-android
 - i686-linux-android
 - x86_64-linux-android
 - x86_64-linux-android
+

+ 2 - 2
examples/ios_demo/mobile.toml → examples/mobile_demo/mobile.toml

@@ -1,6 +1,6 @@
 [app]
 [app]
-name = "rustnl-ios"
-stylized-name = "Rustnl Ios"
+name = "mobile-demo"
+stylized-name = "Mobile Demo"
 domain = "example.com"
 domain = "example.com"
 template-pack = "wry"
 template-pack = "wry"
 
 

+ 16 - 6
examples/ios_demo/src/lib.rs → examples/mobile_demo/src/lib.rs

@@ -1,13 +1,22 @@
 use anyhow::Result;
 use anyhow::Result;
 #[cfg(target_os = "android")]
 #[cfg(target_os = "android")]
 use wry::android_binding;
 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")]
 #[cfg(target_os = "android")]
 fn init_logging() {
 fn init_logging() {
     android_logger::init_once(
     android_logger::init_once(
         android_logger::Config::default()
         android_logger::Config::default()
             .with_min_level(log::Level::Trace)
             .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"))]
 #[cfg(any(target_os = "android", target_os = "ios"))]
 pub extern "C" fn start_app() {
 pub extern "C" fn start_app() {
     #[cfg(target_os = "android")]
     #[cfg(target_os = "android")]
-    android_binding!(com_example, android_taurio, _start_app);
+    android_binding!(com_example, mobile_demo, _start_app);
     #[cfg(target_os = "ios")]
     #[cfg(target_os = "ios")]
     _start_app()
     _start_app()
 }
 }
@@ -46,11 +55,12 @@ pub fn main() -> Result<()> {
     init_logging();
     init_logging();
 
 
     use dioxus::prelude::*;
     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(())
     Ok(())
 }
 }

+ 10 - 10
packages/desktop/src/lib.rs

@@ -123,16 +123,16 @@ pub fn launch_with_props<P: 'static>(root: Component<P>, props: P, cfg: Config)
     let proxy = event_loop.create_proxy();
     let proxy = event_loop.create_proxy();
 
 
     // Intialize hot reloading if it is enabled
     // 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*
     // We start the tokio runtime *on this thread*
     // Any future we poll later will use this runtime to spawn tasks and for IO
     // Any future we poll later will use this runtime to spawn tasks and for IO