Skip to content

Commit

Permalink
Merge pull request #2087 from DioxusLabs/jk/mobile-fixes
Browse files Browse the repository at this point in the history
Fix mobile issues
  • Loading branch information
jkelleyrtp committed Mar 16, 2024
2 parents fe2c17f + f9f9027 commit cba3abc
Show file tree
Hide file tree
Showing 10 changed files with 1,213 additions and 805 deletions.
479 changes: 45 additions & 434 deletions Cargo.lock

Large diffs are not rendered by default.

1,459 changes: 1,113 additions & 346 deletions examples/mobile_demo/Cargo.lock

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions examples/mobile_demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ frameworks = ["WebKit"]
anyhow = "1.0.56"
log = "0.4.11"
wry = "0.35.0"
dioxus = { path = "../../packages/dioxus" }
dioxus-desktop = { path = "../../packages/desktop", features = [
"tokio_runtime",
], default-features = false }
dioxus = { path = "../../packages/dioxus", features = ["mobile"]}


[target.'cfg(target_os = "android")'.dependencies]
Expand Down
22 changes: 11 additions & 11 deletions examples/mobile_demo/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use anyhow::Result;
use dioxus::desktop::Config;
use dioxus::mobile::Config;
use dioxus::prelude::*;

#[cfg(target_os = "android")]
use wry::android_binding;
use dioxus::mobile::wry::android_binding;

#[cfg(target_os = "android")]
fn init_logging() {
Expand Down Expand Up @@ -49,17 +50,19 @@ pub fn main() -> Result<()> {

// 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
LaunchBuilder::new().cfg(
// 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()),
);
LaunchBuilder::mobile()
.with_cfg(
// 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()),
)
.launch(app);

Ok(())
}

fn app() -> Element {
let items = cx.use_hook(|| vec![1, 2, 3]);
let mut items = use_signal(|| vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);

log::debug!("Hello from the app");

Expand All @@ -74,10 +77,7 @@ fn app() -> Element {
border: "1px solid black",
button {
onclick: move |_| {
println!("Clicked!");
items.push(items.len());
cx.needs_update_any(ScopeId::ROOT);
println!("Requested update");
},
"Add item"
}
Expand Down
9 changes: 5 additions & 4 deletions packages/desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ dioxus-html = { workspace = true, features = [
"eval",
] }
dioxus-interpreter-js = { workspace = true, features = ["binary-protocol"] }
dioxus-hot-reload = { workspace = true, optional = true }
dioxus-cli-config = { workspace = true }
generational-box = { workspace = true }

serde = "1.0.136"
serde_json = "1.0.79"
thiserror = { workspace = true }
tracing = { workspace = true }
wry = { version = "0.35.0", default-features = false, features = [
wry = { version = "0.37.0", default-features = false, features = [
"os-webview",
"protocol",
"file-drop",
Expand All @@ -49,12 +48,14 @@ dioxus-hooks = { workspace = true }
futures-util = { workspace = true }
urlencoding = "2.1.2"
async-trait = "0.1.68"
tao = { version = "0.24.0", features = ["rwh_05"] }
tao = { version = "0.26.1", features = ["rwh_05"] }

[target.'cfg(any(target_os = "windows",target_os = "macos",target_os = "linux",target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))'.dependencies]
global-hotkey = "0.5.0"
rfd = "0.12"
muda = "0.11.3"
# hotreload only works on desktop platforms.... mobile is still wip
dioxus-hot-reload = { workspace = true, optional = true }

[target.'cfg(target_os = "ios")'.dependencies]
objc = "0.2.7"
Expand All @@ -65,7 +66,7 @@ core-foundation = "0.9.3"
objc = "0.2.7"

[features]
default = ["tokio_runtime", "hot-reload", "wry/objc-exception"]
default = ["tokio_runtime", "wry/objc-exception", "hot-reload"]
tokio_runtime = ["tokio"]
fullscreen = ["wry/fullscreen"]
transparent = ["wry/transparent"]
Expand Down
21 changes: 18 additions & 3 deletions packages/desktop/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ impl App {
app.set_global_hotkey_handler();

// Allow hotreloading to work - but only in debug mode
#[cfg(all(feature = "hot-reload", debug_assertions))]
#[cfg(all(
feature = "hot-reload",
debug_assertions,
not(target_os = "android"),
not(target_os = "ios")
))]
app.connect_hotreload();

(event_loop, app)
Expand All @@ -99,7 +104,12 @@ impl App {
self.shared.shortcut_manager.call_handlers(event);
}

#[cfg(all(feature = "hot-reload", debug_assertions))]
#[cfg(all(
feature = "hot-reload",
debug_assertions,
not(target_os = "android"),
not(target_os = "ios")
))]
pub fn connect_hotreload(&self) {
dioxus_hot_reload::connect({
let proxy = self.shared.proxy.clone();
Expand Down Expand Up @@ -265,7 +275,12 @@ impl App {
view.desktop_context.send_edits();
}

#[cfg(all(feature = "hot-reload", debug_assertions))]
#[cfg(all(
feature = "hot-reload",
debug_assertions,
not(target_os = "android"),
not(target_os = "ios")
))]
pub fn handle_hot_reload_msg(&mut self, msg: dioxus_hot_reload::HotReloadMsg) {
match msg {
dioxus_hot_reload::HotReloadMsg::UpdateTemplate(template) => {
Expand Down
7 changes: 6 additions & 1 deletion packages/desktop/src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ pub enum UserWindowEvent {
Ipc { id: WindowId, msg: IpcMessage },

/// Handle a hotreload event, basically telling us to update our templates
#[cfg(all(feature = "hot-reload", debug_assertions))]
#[cfg(all(
feature = "hot-reload",
debug_assertions,
not(target_os = "android"),
not(target_os = "ios")
))]
HotReloadEvent(dioxus_hot_reload::HotReloadMsg),

/// Create a new window
Expand Down
7 changes: 6 additions & 1 deletion packages/desktop/src/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ pub fn launch_virtual_dom_blocking(virtual_dom: VirtualDom, desktop_config: Conf
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
UserWindowEvent::GlobalHotKeyEvent(evnt) => app.handle_global_hotkey(evnt),

#[cfg(all(feature = "hot-reload", debug_assertions))]
#[cfg(all(
feature = "hot-reload",
debug_assertions,
not(target_os = "android"),
not(target_os = "ios")
))]
UserWindowEvent::HotReloadEvent(msg) => app.handle_hot_reload_msg(msg),

UserWindowEvent::Ipc { id, msg } => match msg.method() {
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ impl WebviewInstance {
webview = webview
.with_transparent(cfg.window.window.transparent)
.with_url("dioxus://index.html/")
.unwrap()
.with_ipc_handler(ipc_handler)
.with_navigation_handler(|var| var.contains("dioxus")) // prevent all navigations
.with_asynchronous_custom_protocol(String::from("dioxus"), request_handler)
Expand Down Expand Up @@ -222,6 +221,7 @@ impl WebviewInstance {
}
}

#[allow(unused)]
pub fn kick_stylsheets(&self) {
// run eval in the webview to kick the stylesheets by appending a query string
// we should do something less clunky than this
Expand Down
7 changes: 7 additions & 0 deletions packages/dioxus/src/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,10 @@ pub fn launch_desktop(app: fn() -> Element) {
pub fn launch_fullstack(app: fn() -> Element) {
LaunchBuilder::fullstack().launch(app)
}

#[cfg(feature = "mobile")]
#[cfg_attr(docsrs, doc(cfg(feature = "mobile")))]
/// Launch your mobile application without any additional configuration. See [`LaunchBuilder`] for more options.
pub fn launch_mobile(app: fn() -> Element) {
LaunchBuilder::mobile().launch(app)
}

0 comments on commit cba3abc

Please sign in to comment.