|
@@ -2,6 +2,8 @@ use crate::controller::DesktopController;
|
|
use dioxus_core::ScopeState;
|
|
use dioxus_core::ScopeState;
|
|
use wry::application::event_loop::ControlFlow;
|
|
use wry::application::event_loop::ControlFlow;
|
|
use wry::application::event_loop::EventLoopProxy;
|
|
use wry::application::event_loop::EventLoopProxy;
|
|
|
|
+#[cfg(target_os = "ios")]
|
|
|
|
+use wry::application::platform::ios::WindowExtIOS;
|
|
use wry::application::window::Fullscreen as WryFullscreen;
|
|
use wry::application::window::Fullscreen as WryFullscreen;
|
|
|
|
|
|
use UserWindowEvent::*;
|
|
use UserWindowEvent::*;
|
|
@@ -134,6 +136,18 @@ impl DesktopContext {
|
|
pub fn eval(&self, script: impl std::string::ToString) {
|
|
pub fn eval(&self, script: impl std::string::ToString) {
|
|
let _ = self.proxy.send_event(Eval(script.to_string()));
|
|
let _ = self.proxy.send_event(Eval(script.to_string()));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /// Push view
|
|
|
|
+ #[cfg(target_os = "ios")]
|
|
|
|
+ pub fn push_view(&self, view: objc_id::ShareId<objc::runtime::Object>) {
|
|
|
|
+ let _ = self.proxy.send_event(PushView(view));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// Push view
|
|
|
|
+ #[cfg(target_os = "ios")]
|
|
|
|
+ pub fn pop_view(&self) {
|
|
|
|
+ let _ = self.proxy.send_event(PopView);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
#[derive(Debug)]
|
|
#[derive(Debug)]
|
|
@@ -164,6 +178,11 @@ pub enum UserWindowEvent {
|
|
DevTool,
|
|
DevTool,
|
|
|
|
|
|
Eval(String),
|
|
Eval(String),
|
|
|
|
+
|
|
|
|
+ #[cfg(target_os = "ios")]
|
|
|
|
+ PushView(objc_id::ShareId<objc::runtime::Object>),
|
|
|
|
+ #[cfg(target_os = "ios")]
|
|
|
|
+ PopView,
|
|
}
|
|
}
|
|
|
|
|
|
pub(super) fn handler(
|
|
pub(super) fn handler(
|
|
@@ -231,6 +250,32 @@ pub(super) fn handler(
|
|
log::warn!("Eval script error: {e}");
|
|
log::warn!("Eval script error: {e}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ #[cfg(target_os = "ios")]
|
|
|
|
+ PushView(view) => unsafe {
|
|
|
|
+ use objc::runtime::Object;
|
|
|
|
+ use objc::*;
|
|
|
|
+ assert!(is_main_thread());
|
|
|
|
+ let ui_view = window.ui_view() as *mut Object;
|
|
|
|
+ let ui_view_frame: *mut Object = msg_send![ui_view, frame];
|
|
|
|
+ let _: () = msg_send![view, setFrame: ui_view_frame];
|
|
|
|
+ let _: () = msg_send![view, setAutoresizingMask: 31];
|
|
|
|
+
|
|
|
|
+ let ui_view_controller = window.ui_view_controller() as *mut Object;
|
|
|
|
+ let _: () = msg_send![ui_view_controller, setView: view];
|
|
|
|
+ desktop.views.push(ui_view);
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ #[cfg(target_os = "ios")]
|
|
|
|
+ PopView => unsafe {
|
|
|
|
+ use objc::runtime::Object;
|
|
|
|
+ use objc::*;
|
|
|
|
+ assert!(is_main_thread());
|
|
|
|
+ if let Some(view) = desktop.views.pop() {
|
|
|
|
+ let ui_view_controller = window.ui_view_controller() as *mut Object;
|
|
|
|
+ let _: () = msg_send![ui_view_controller, setView: view];
|
|
|
|
+ }
|
|
|
|
+ },
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -240,3 +285,13 @@ pub fn use_eval<S: std::string::ToString>(cx: &ScopeState) -> &dyn Fn(S) {
|
|
|
|
|
|
cx.use_hook(|| move |script| desktop.eval(script))
|
|
cx.use_hook(|| move |script| desktop.eval(script))
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+#[cfg(target_os = "ios")]
|
|
|
|
+fn is_main_thread() -> bool {
|
|
|
|
+ use objc::runtime::{Class, BOOL, NO};
|
|
|
|
+ use objc::*;
|
|
|
|
+
|
|
|
|
+ let cls = Class::get("NSThread").unwrap();
|
|
|
|
+ let result: BOOL = unsafe { msg_send![cls, isMainThread] };
|
|
|
|
+ result != NO
|
|
|
|
+}
|