mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-23 00:50:35 +01:00
a47f721832
This adds an experimental `gpui_ios` backend so GPUI applications can run on iPhone and iPad. It uses typed objc2 UIKit subclasses with Rust-owned application and scene delegates, and it builds on the `gpui_apple` services and Metal rendering already on `main`. UIKit touches go through GPUI's portable touch and gesture handling, and safe-area and keyboard geometry are exposed as window insets. Native text input goes through a focused `UITextInput` bridge. Each field gets its own text-input session, so offsets from one field can't edit another, and GPUI focus is kept when the keyboard is dismissed. The backend is registered with `gpui_platform`, and the PR includes a small standalone Rust example that can be built and run in the iOS simulator. This is initial support, not full desktop or mobile feature parity. Native edit menus and networking/TLS workarounds are deferred to follow-ups, and the Return key and hardware-keyboard shortcuts are not yet delivered as GPUI key events. The backend's unit tests and a native UIKit text-input test pass on the iPhone and iPad simulators, the example runs in the simulator, and it links for physical iOS devices. Release Notes: - [GPUI] Added an experimental iOS platform backend with a standalone Rust example. --------- Co-authored-by: zed-zippy[bot] <234243425+zed-zippy[bot]@users.noreply.github.com>
60 lines
1.7 KiB
Rust
60 lines
1.7 KiB
Rust
#[cfg(target_os = "ios")]
|
|
#[path = "../src/ios/text_input.rs"]
|
|
mod text_input;
|
|
|
|
// Native protocol construction does not need a GPUI window, renderer, or a
|
|
// second text model. This fixture deliberately has no registered input handler.
|
|
#[cfg(target_os = "ios")]
|
|
mod window {
|
|
use gpui::PlatformInputHandler;
|
|
use std::{
|
|
cell::{Cell, RefCell},
|
|
rc::Weak,
|
|
};
|
|
|
|
thread_local! {
|
|
static HANDLER_QUERIES: Cell<usize> = const { Cell::new(0) };
|
|
}
|
|
|
|
pub(crate) fn handler_queries() -> usize {
|
|
HANDLER_QUERIES.with(Cell::get)
|
|
}
|
|
|
|
pub(crate) struct IosWindowState;
|
|
|
|
impl IosWindowState {
|
|
pub(crate) fn with_input_handler<R>(
|
|
&self,
|
|
_callback: impl FnOnce(&mut PlatformInputHandler) -> R,
|
|
) -> Option<R> {
|
|
None
|
|
}
|
|
}
|
|
|
|
#[derive(Default)]
|
|
pub(crate) struct WindowReference(pub(crate) RefCell<Weak<IosWindowState>>);
|
|
|
|
impl WindowReference {
|
|
pub(crate) fn with_window<R>(
|
|
&self,
|
|
callback: impl FnOnce(&IosWindowState) -> R,
|
|
) -> Option<R> {
|
|
HANDLER_QUERIES.with(|queries| queries.set(queries.get() + 1));
|
|
self.0.borrow().upgrade().map(|window| callback(&window))
|
|
}
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
#[cfg(target_os = "ios")]
|
|
{
|
|
let main_thread = objc2::MainThreadMarker::new().expect("native test runs on main thread");
|
|
text_input::tests::native_protocol_smoke_test(main_thread);
|
|
text_input::tests::stale_objects_do_not_route_to_handler(
|
|
main_thread,
|
|
window::handler_queries,
|
|
);
|
|
println!("UIKit text input native protocol smoke test passed");
|
|
}
|
|
}
|