Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
gpui_ios: Add display corner radii and an `on_back_gesture` (#65806)
Anthony Eidc4a82ab1ab95
diff --git a/Cargo.toml b/Cargo.tomlindex 25ed86481ba..a3f1d0a033a 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -711,10 +711,13 @@ objc2-ui-kit = { version = "0.3.2", default-features = false, features = ["NSText","UIApplication","UICommand",+ "UICornerConfiguration",+ "UICornerRadius","UIEvent","UIGeometry","UIGestureRecognizer","UIPanGestureRecognizer",+ "UIScreenEdgePanGestureRecognizer","UIInterface","UIOpenURLContext","UIPasteboard",diff --git a/crates/gpui/src/elements/div.rs b/crates/gpui/src/elements/div.rsindex 6f2781f7643..3de179a91fd 100644--- a/crates/gpui/src/elements/div.rs+++ b/crates/gpui/src/elements/div.rs@@ -16,15 +16,15 @@//! constructed by combining these two systems into an all-in-one element.use crate::{- Action, AnyDrag, AnyElement, AnyTooltip, AnyView, App, Bounds, ClickEvent, DispatchPhase,- Display, Element, ElementId, Entity, EntityId, ExternalDragPayload, ExternalDragPayloadSource,- FileDropEvent, FocusHandle, Global, GlobalElementId, Hitbox, HitboxBehavior, HitboxId,- InspectorElementId, IntoElement, IsZero, KeyContext, KeyDownEvent, KeyUpEvent, KeyboardButton,- KeyboardClickEvent, LayoutId, LongPressEvent, ModifiersChangedEvent, MouseButton,- MouseClickEvent, MouseDownEvent, MouseExitEvent, MouseMoveEvent, MousePressureEvent,- MouseUpEvent, OngoingScroll, Overflow, ParentElement, PinchEvent, Pixels, Point, Render,- ScrollEvent, SharedString, Size, Style, StyleRefinement, Styled, Task, TooltipId, TouchPhase,- Visibility, Window, WindowControlArea, point, px, size,+ Action, AnyDrag, AnyElement, AnyTooltip, AnyView, App, BackGestureEvent, Bounds, ClickEvent,+ DispatchPhase, Display, Element, ElementId, Entity, EntityId, ExternalDragPayload,+ ExternalDragPayloadSource, FileDropEvent, FocusHandle, Global, GlobalElementId, Hitbox,+ HitboxBehavior, HitboxId, InspectorElementId, IntoElement, IsZero, KeyContext, KeyDownEvent,+ KeyUpEvent, KeyboardButton, KeyboardClickEvent, LayoutId, LongPressEvent,+ ModifiersChangedEvent, MouseButton, MouseClickEvent, MouseDownEvent, MouseExitEvent,+ MouseMoveEvent, MousePressureEvent, MouseUpEvent, OngoingScroll, Overflow, ParentElement,+ PinchEvent, Pixels, Point, Render, ScrollEvent, SharedString, Size, Style, StyleRefinement,+ Styled, Task, TooltipId, TouchPhase, Visibility, Window, WindowControlArea, point, px, size,};use collections::HashMap;use gpui_util::ResultExt;@@ -417,6 +417,24 @@ impl Interactivity {}));}+ /// Bind the given callback to back-navigation gestures that start over this element.+ /// The imperative API equivalent to [`InteractiveElement::on_back_gesture`].+ ///+ /// See [`Context::listener`](crate::Context::listener) to get access to a view's state from this callback.+ pub fn on_back_gesture(+ &mut self,+ listener: impl Fn(&BackGestureEvent, &mut Window, &mut App) + 'static,+ ) {+ self.back_gesture_listeners+ .push(Box::new(move |event, phase, hitbox, window, cx| {+ if phase == DispatchPhase::Bubble && hitbox.is_hovered(window) {+ (listener)(event, window, cx);+ window.prevent_default();+ cx.stop_propagation();+ }+ }));+ }+/// Bind the given callback to pinch gesture events during the capture phase.////// See [`Context::listener`](crate::Context::listener) to get access to a view's state from this callback.@@ -1089,6 +1107,20 @@ pub trait InteractiveElement: Sized {self}+ /// Bind the given callback to back-navigation gestures that start over this+ /// element, such as the iOS swipe from the leading screen edge. The innermost+ /// element with a back listener claims the gesture and receives every phase.+ /// The fluent API equivalent to [`Interactivity::on_back_gesture`].+ ///+ /// See [`Context::listener`](crate::Context::listener) to get access to a view's state from this callback.+ fn on_back_gesture(+ mut self,+ listener: impl Fn(&BackGestureEvent, &mut Window, &mut App) + 'static,+ ) -> Self {+ self.interactivity().on_back_gesture(listener);+ self+ }+/// Bind the given callback to pinch gesture events during the capture phase./// The fluent API equivalent to [`Interactivity::capture_pinch`].///@@ -1749,6 +1781,9 @@ pub(crate) type ScrollListener =pub(crate) type PinchListener =Box<dyn Fn(&PinchEvent, DispatchPhase, &Hitbox, &mut Window, &mut App) + 'static>;+pub(crate) type BackGestureListener =+ Box<dyn Fn(&BackGestureEvent, DispatchPhase, &Hitbox, &mut Window, &mut App) + 'static>;+pub(crate) type ClickListener = Rc<dyn Fn(&ClickEvent, &mut Window, &mut App) + 'static>;/// Controls how [`StatefulInteractiveElement::on_hover`] responds to key presses while the mouse@@ -2186,6 +2221,7 @@ pub struct Interactivity {pub(crate) file_drop_exit_listeners: Vec<FileDropExitListener>,pub(crate) scroll_listeners: Vec<ScrollListener>,pub(crate) pinch_listeners: Vec<PinchListener>,+ pub(crate) back_gesture_listeners: Vec<BackGestureListener>,pub(crate) key_down_listeners: Vec<KeyDownListener>,pub(crate) key_up_listeners: Vec<KeyUpListener>,pub(crate) modifiers_changed_listeners: Vec<ModifiersChangedListener>,@@ -2439,6 +2475,7 @@ impl Interactivity {|| !self.aux_click_listeners.is_empty()|| !self.scroll_listeners.is_empty()|| self.has_pinch_listeners()+ || !self.back_gesture_listeners.is_empty()|| self.drag_listener.is_some()|| !self.drop_listeners.is_empty()|| !self.drag_over_styles.is_empty()@@ -2857,6 +2894,13 @@ impl Interactivity {})}+ for listener in self.back_gesture_listeners.drain(..) {+ let hitbox = hitbox.clone();+ window.on_mouse_event(move |event: &BackGestureEvent, phase, window, cx| {+ listener(event, phase, &hitbox, window, cx);+ })+ }+if self.hover_style.is_some()|| self.base_style.mouse_cursor.is_some()|| cx.active_drag.is_some() && !self.drag_over_styles.is_empty()diff --git a/crates/gpui/src/gestures.rs b/crates/gpui/src/gestures.rsindex 0191db5406d..665da3dd0e5 100644--- a/crates/gpui/src/gestures.rs+++ b/crates/gpui/src/gestures.rs@@ -397,6 +397,49 @@ impl InputEvent for TouchDragEvent {impl GestureEvent for TouchDragEvent {}impl MouseEvent for TouchDragEvent {}+/// A back-navigation gesture, such as the iOS swipe from the leading screen+/// edge.+///+/// Elements receive it through+/// [`InteractiveElement::on_back_gesture`](crate::InteractiveElement::on_back_gesture).+/// The innermost element under [`Self::start_position`] claims the whole+/// gesture when it starts; the platform cancels the gesture if no element does.+/// Every phase is delivered at the start position, so the claiming element+/// should stay in place while it animates its contents.+#[derive(Clone, Debug, Default)]+pub struct BackGestureEvent {+ /// The phase of the gesture.+ pub phase: BackGesturePhase,+ /// Where the gesture started.+ pub start_position: Point<Pixels>,+ /// How far the gesture has travelled toward going back, from 0 to 1.+ pub progress: f32,+}++/// The phase of a [`BackGestureEvent`].+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]+pub enum BackGesturePhase {+ /// The gesture began. Claiming it here routes the remaining phases to the+ /// same element.+ #[default]+ Started,+ /// The gesture moved; [`BackGestureEvent::progress`] changed.+ Progressed,+ /// The gesture ended and the platform decided to go back.+ Committed,+ /// The gesture ended without going back.+ Cancelled,+}++impl Sealed for BackGestureEvent {}+impl InputEvent for BackGestureEvent {+ fn to_platform_input(self) -> PlatformInput {+ PlatformInput::BackGesture(self)+ }+}+impl GestureEvent for BackGestureEvent {}+impl MouseEvent for BackGestureEvent {}+/// A phased long-press gesture recognized from a touch.#[derive(Clone, Debug)]pub struct LongPressEvent {diff --git a/crates/gpui/src/interactive.rs b/crates/gpui/src/interactive.rsindex fb6691b3f34..cfb1410c788 100644--- a/crates/gpui/src/interactive.rs+++ b/crates/gpui/src/interactive.rs@@ -1,6 +1,6 @@use crate::{- Bounds, Capslock, Context, Empty, IntoElement, Keystroke, LongPressEvent, Modifiers, Pixels,- Point, Render, TouchDragEvent, Window, point, seal::Sealed,+ BackGestureEvent, Bounds, Capslock, Context, Empty, IntoElement, Keystroke, LongPressEvent,+ Modifiers, Pixels, Point, Render, TouchDragEvent, Window, point, seal::Sealed,};use smallvec::SmallVec;use std::{any::Any, fmt::Debug, ops::Deref, path::PathBuf};@@ -815,6 +815,8 @@ pub enum PlatformInput {LongPress(LongPressEvent),/// A direct touch drag claimed by an element.TouchDrag(TouchDragEvent),+ /// A back-navigation gesture recognized by the platform.+ BackGesture(BackGestureEvent),/// Files were dragged and dropped onto the window.FileDrop(FileDropEvent),/// A raw touch event on a touch screen.@@ -836,6 +838,7 @@ impl PlatformInput {PlatformInput::Pinch(event) => Some(event),PlatformInput::LongPress(event) => Some(event),PlatformInput::TouchDrag(event) => Some(event),+ PlatformInput::BackGesture(event) => Some(event),PlatformInput::FileDrop(event) => Some(event),PlatformInput::Touch(_) => None,}@@ -855,6 +858,7 @@ impl PlatformInput {PlatformInput::Pinch(_) => None,PlatformInput::LongPress(_) => None,PlatformInput::TouchDrag(_) => None,+ PlatformInput::BackGesture(_) => None,PlatformInput::FileDrop(_) => None,PlatformInput::Touch(_) => None,}@@ -876,6 +880,7 @@ impl PlatformInput {PlatformInput::Pinch(_) => "pinch",PlatformInput::LongPress(_) => "long_press",PlatformInput::TouchDrag(_) => "touch_drag",+ PlatformInput::BackGesture(_) => "back_gesture",PlatformInput::FileDrop(_) => "file_drop",PlatformInput::Touch(_) => "touch",}diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rsindex 42841ac541b..e2fb5536ad4 100644--- a/crates/gpui/src/platform.rs+++ b/crates/gpui/src/platform.rs@@ -36,7 +36,7 @@ pub(crate) type PlatformScreenCaptureFrame =objc2_core_foundation::CFRetained<objc2_core_video::CVImageBuffer>;use crate::{- Action, AnyWindowHandle, App, AsyncWindowContext, BackgroundExecutor, Bounds,+ Action, AnyWindowHandle, App, AsyncWindowContext, BackgroundExecutor, Bounds, Corners,DEFAULT_WINDOW_SIZE, DevicePixels, DispatchEventResult, Edges, ExternalDragPayload, Font,FontId, FontMetrics, FontRun, ForegroundExecutor, GlyphId, GpuSpecs, Hsla, ImageSource, Keymap,LineLayout, MissingGlyphSink, Pixels, PlatformGestures, PlatformInput, Point, Priority,@@ -1166,6 +1166,11 @@ pub struct WindowInsets {/// (iOS: derived from `keyboardWillShow`/frame-change notifications./// Android: `WindowInsets.Type.ime()`.)pub ime: Edges<Pixels>,+ /// The radii of the window's visible corners where the display rounds+ /// them, and zero where corners are square or the platform can't say.+ /// Content inset from an edge by `d` lines up with the display by using a+ /// radius of `radius - d`. (iOS 26+: a concentric `UICornerConfiguration`.)+ pub corner_radii: Corners<Pixels>,}impl WindowInsets {diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rsindex b5fdcd31eb3..52ee1b44812 100644--- a/crates/gpui/src/window.rs+++ b/crates/gpui/src/window.rs@@ -5761,6 +5761,10 @@ impl Window {self.mouse_position = touch_drag.start_position;PlatformInput::TouchDrag(touch_drag)}+ PlatformInput::BackGesture(back) => {+ self.mouse_position = back.start_position;+ PlatformInput::BackGesture(back)+ }PlatformInput::KeyDown(_) | PlatformInput::KeyUp(_) => event,};@@ -7919,14 +7923,14 @@ mod tests {};use crate::{- AnyWindowHandle, AppContext as _, Bounds, ContentMask, Context, DispatchPhase,- DragMoveEvent, Empty, ExternalDragPayload, ExternalPaths, FileDragPaths, FileDropEvent,- FocusHandle, InputEvent as _, InteractiveElement as _, IntoElement, KeyDownEvent,- Keystroke, LongPressEvent, MouseButton, MouseDownEvent, MouseMoveEvent, ParentElement,- Pixels, PlatformInput, Point, Render, RequestFrameOptions, ScaledPixels,- StatefulInteractiveElement as _, Styled, TestAppContext, TouchDragEvent, TouchEvent,- TouchId, TouchPhase, Underline, UnderlineStyle, Window, WindowAppearance, WindowOptions,- canvas, div, hsla, point, px, size,+ AnyWindowHandle, AppContext as _, BackGestureEvent, BackGesturePhase, Bounds, ContentMask,+ Context, DispatchPhase, DragMoveEvent, Empty, ExternalDragPayload, ExternalPaths,+ FileDragPaths, FileDropEvent, FocusHandle, InputEvent as _, InteractiveElement as _,+ IntoElement, KeyDownEvent, Keystroke, LongPressEvent, MouseButton, MouseDownEvent,+ MouseMoveEvent, ParentElement, Pixels, PlatformInput, Point, Render, RequestFrameOptions,+ ScaledPixels, StatefulInteractiveElement as _, Styled, TestAppContext, TouchDragEvent,+ TouchEvent, TouchId, TouchPhase, Underline, UnderlineStyle, Window, WindowAppearance,+ WindowOptions, canvas, div, hsla, point, px, size,};#[gpui::test]@@ -8369,6 +8373,7 @@ mod tests {bottom: px(350.),..Default::default()},+ ..Default::default()};platform_window.simulate_insets_change(insets.clone());assert!(platform_window.frame_wake_count() > wakes);@@ -9245,6 +9250,58 @@ mod tests {);}+ #[gpui::test]+ fn back_gesture_is_claimed_by_the_innermost_listener(cx: &mut TestAppContext) {+ let claims = Rc::new(RefCell::new(Vec::new()));+ let window = cx.add_window({+ let claims = claims.clone();+ move |_, _| BackListeners { claims }+ });+ let dispatch_back = |cx: &mut TestAppContext, x: f32| {+ window+ .update(cx, |_, window, cx| {+ window+ .dispatch_event(+ BackGestureEvent {+ phase: BackGesturePhase::Started,+ start_position: point(px(x), px(10.)),+ progress: 0.,+ }+ .to_platform_input(),+ cx,+ )+ .default_prevented+ })+ .unwrap()+ };+ assert!(dispatch_back(cx, 10.));+ assert!(dispatch_back(cx, 80.));+ assert!(!dispatch_back(cx, 150.));+ assert_eq!(claims.borrow().as_slice(), ["inner", "outer"]);+ }++ struct BackListeners {+ claims: Rc<RefCell<Vec<&'static str>>>,+ }++ impl Render for BackListeners {+ fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {+ let claim = |name: &'static str| {+ let claims = self.claims.clone();+ move |_: &BackGestureEvent, _: &mut Window, _: &mut crate::App| {+ claims.borrow_mut().push(name)+ }+ };+ div().size_full().child(+ div()+ .w(px(100.))+ .h_full()+ .on_back_gesture(claim("outer"))+ .child(div().w(px(50.)).h_full().on_back_gesture(claim("inner"))),+ )+ }+ }+struct TouchDragListener {events: Rc<RefCell<Vec<(TouchPhase, Pixels)>>>,}diff --git a/crates/gpui_ios/src/ios/events.rs b/crates/gpui_ios/src/ios/events.rsindex a730070f09f..b5ae74c74ff 100644--- a/crates/gpui_ios/src/ios/events.rs+++ b/crates/gpui_ios/src/ios/events.rs@@ -1,14 +1,65 @@//! Conversion from UIKit events to GPUI input events.use gpui::{- Modifiers, Pixels, Point, ScrollDelta, ScrollEvent, ScrollSource, TouchId, TouchPhase, px,+ BackGestureEvent, BackGesturePhase, Modifiers, Pixels, Point, ScrollDelta, ScrollEvent,+ ScrollSource, TouchId, TouchPhase, px,};use objc2_core_foundation::CGPoint;use objc2_ui_kit::{- UIGestureRecognizerState, UIKeyModifierFlags, UIPanGestureRecognizer, UITouch, UITouchPhase,- UIView,+ UIGestureRecognizerState, UIKeyModifierFlags, UIPanGestureRecognizer, UIRectEdge,+ UIScreenEdgePanGestureRecognizer, UITouch, UITouchPhase, UIView,};+/// A release faster than this, in points per second toward going back, commits+/// a back gesture regardless of how far it travelled.+const BACK_COMMIT_VELOCITY: f64 = 300.;++/// Converts a step of the screen-edge back gesture, whose `Started` phase was+/// already delivered when the recognizer asked to begin.+///+/// Like `UINavigationController`, a release commits when the gesture is past+/// halfway without flicking back, or when it flicks forward quickly. Returns+/// `None` for states that carry no step.+pub fn back_event(+ recognizer: &UIScreenEdgePanGestureRecognizer,+ view: &UIView,+ start_position: Point<Pixels>,+) -> Option<BackGestureEvent> {+ // Gestures from the right edge move content leftward toward going back.+ let direction = if recognizer.edges() == UIRectEdge::Right {+ -1.+ } else {+ 1.+ };+ let width = view.bounds().size.width.max(1.);+ let travel = recognizer.translationInView(Some(view)).x * direction;+ let progress = (travel / width).clamp(0., 1.);+ let phase = match recognizer.state() {+ UIGestureRecognizerState::Began | UIGestureRecognizerState::Changed => {+ BackGesturePhase::Progressed+ }+ UIGestureRecognizerState::Ended => {+ let velocity = recognizer.velocityInView(Some(view)).x * direction;+ if velocity > BACK_COMMIT_VELOCITY+ || (progress > 0.5 && velocity > -BACK_COMMIT_VELOCITY)+ {+ BackGesturePhase::Committed+ } else {+ BackGesturePhase::Cancelled+ }+ }+ UIGestureRecognizerState::Cancelled | UIGestureRecognizerState::Failed => {+ BackGesturePhase::Cancelled+ }+ _ => return None,+ };+ Some(BackGestureEvent {+ phase,+ start_position,+ progress: progress as f32,+ })+}+pub fn touch_location_in_view(touch: &UITouch, view: &UIView) -> Point<Pixels> {let location = touch.locationInView(Some(view));Point::new(px(location.x as f32), px(location.y as f32))diff --git a/crates/gpui_ios/src/ios/window.rs b/crates/gpui_ios/src/ios/window.rsindex be68f04ac53..685f575986d 100644--- a/crates/gpui_ios/src/ios/window.rs+++ b/crates/gpui_ios/src/ios/window.rs@@ -13,16 +13,16 @@ use super::events::*;use super::text_input::TextInputView;use super::{CallbackSlot, IosDisplay, platform::IosPlatformState};use gpui::{- AnyWindowHandle, Bounds, Capslock, DevicePixels, DispatchEventResult, DisplayId, Edges,- GpuSpecs, Modifiers, Pixels, PlatformAtlas, PlatformDisplay, PlatformInput,- PlatformInputHandler, PlatformWindow, Point, PromptButton, PromptLevel, RequestFrameOptions,- Scene, Size, TextInputConfiguration, TextInputStateChange, TouchEvent, TouchId, TouchPhase,- WindowAppearance, WindowBackgroundAppearance, WindowBounds, WindowControlArea, WindowInsets,- WindowParams, WindowVisibility, px, size,+ AnyWindowHandle, BackGestureEvent, BackGesturePhase, Bounds, Capslock, Corners, DevicePixels,+ DispatchEventResult, DisplayId, Edges, GpuSpecs, Modifiers, Pixels, PlatformAtlas,+ PlatformDisplay, PlatformInput, PlatformInputHandler, PlatformWindow, Point, PromptButton,+ PromptLevel, RequestFrameOptions, Scene, Size, TextInputConfiguration, TextInputStateChange,+ TouchEvent, TouchId, TouchPhase, WindowAppearance, WindowBackgroundAppearance, WindowBounds,+ WindowControlArea, WindowInsets, WindowParams, WindowVisibility, px, size,};use gpui_apple::metal_renderer::{Context as MetalContext, MetalRenderer};use objc2::rc::Retained;-use objc2::runtime::{AnyClass, AnyObject};+use objc2::runtime::{AnyClass, AnyObject, ProtocolObject};use objc2::{ClassType, DefinedClass, MainThreadMarker, MainThreadOnly, define_class, msg_send, sel,};@@ -36,9 +36,11 @@ use objc2_ui_kit::{UIKeyboardWillChangeFrameNotification, UIKeyboardWillHideNotification, UIStatusBarStyle,};use objc2_ui_kit::{- UIEvent, UIPanGestureRecognizer, UIScreen, UIScrollTypeMask, UITouch, UITraitCollection,- UITraitEnvironment, UIUserInterfaceStyle, UIView, UIViewAutoresizing, UIViewController,- UIWindow, UIWindowScene,+ UICornerConfiguration, UICornerRadius, UIEvent, UIGestureRecognizer,+ UIGestureRecognizerDelegate, UIPanGestureRecognizer, UIRectCorner, UIRectEdge, UIScreen,+ UIScreenEdgePanGestureRecognizer, UIScrollTypeMask, UITouch, UITraitCollection,+ UITraitEnvironment, UIUserInterfaceLayoutDirection, UIUserInterfaceStyle, UIView,+ UIViewAutoresizing, UIViewController, UIWindow, UIWindowScene,};use parking_lot::Mutex;use raw_window_handle::{HasDisplayHandle, HasWindowHandle, UiKitDisplayHandle, UiKitWindowHandle};@@ -188,6 +190,21 @@ define_class!(.with_window(|window| window.handle_scroll(recognizer));}+ #[unsafe(method(handleBackGesture:))]+ fn handle_back_gesture(&self, recognizer: &UIScreenEdgePanGestureRecognizer) {+ self.ivars()+ .with_window(|window| window.handle_back_gesture(recognizer));+ }+ }++ unsafe impl UIGestureRecognizerDelegate for MetalView {+ // Only the back-gesture recognizer uses this view as its delegate.+ #[unsafe(method(gestureRecognizerShouldBegin:))]+ fn gesture_recognizer_should_begin(&self, recognizer: &UIGestureRecognizer) -> bool {+ self.ivars()+ .with_window(|window| window.begin_back_gesture(recognizer))+ .unwrap_or(false)+ }});@@ -262,6 +279,8 @@ pub(crate) struct IosWindowState {appearance_changed_callback: CallbackSlot<Box<dyn FnMut()>>,insets_changed_callback: CallbackSlot<Box<dyn FnMut(WindowInsets)>>,keyboard_dismiss_touch: Cell<Option<KeyboardDismissTouch>>,+ /// Where the back gesture an element claimed started, while it runs.+ back_gesture_start: Cell<Option<Point<Pixels>>>,keyboard_height: Cell<f32>,/// Current mouse position (from touch)mouse_position: Cell<Point<Pixels>>,@@ -315,6 +334,17 @@ impl IosWindow {view.setUserInteractionEnabled(true);view.setMultipleTouchEnabled(true);+ // UIKit has no public API for the display's corner radius, but since+ // iOS 26 a view filling the window with a container-concentric corner+ // configuration resolves its radii to the display's. This only sets the+ // layer's corner radius; without `masksToBounds` the Metal drawable is+ // not clipped.+ if reports_corner_radii(&view) {+ view.setCornerConfiguration(&UICornerConfiguration::configurationWithRadius(+ &UICornerRadius::containerConcentricRadius(),+ ));+ }+// Trackpad and mouse-wheel scrolling reaches UIKit apps only through a// pan recognizer that accepts scroll types. With no allowed touch types// it never claims finger touches, so those keep reaching `touchesBegan`@@ -333,6 +363,30 @@ impl IosWindow {scroll_recognizer.setCancelsTouchesInView(false);view.addGestureRecognizer(&scroll_recognizer);+ // The leading-edge swipe is iOS's back gesture. The delegate lets it+ // begin only when an element claims it; it then cancels the touches it+ // took over, so GPUI's own recognizer abandons any pan it had started.+ let back_target: &AnyObject = &view;+ // SAFETY: `MetalView` implements `handleBackGesture:` and owns the recognizer.+ let back_recognizer = unsafe {+ UIScreenEdgePanGestureRecognizer::initWithTarget_action(+ UIScreenEdgePanGestureRecognizer::alloc(main_thread),+ Some(back_target),+ Some(sel!(handleBackGesture:)),+ )+ };+ back_recognizer.setEdges(+ if view.effectiveUserInterfaceLayoutDirection()+ == UIUserInterfaceLayoutDirection::RightToLeft+ {+ UIRectEdge::Right+ } else {+ UIRectEdge::Left+ },+ );+ back_recognizer.setDelegate(Some(ProtocolObject::from_ref(&*view)));+ view.addGestureRecognizer(&back_recognizer);+let view_controller = ViewController::new(main_thread);view_controller.setView(Some(&view));window.setRootViewController(Some(&view_controller));@@ -387,6 +441,7 @@ impl IosWindow {appearance_changed_callback: CallbackSlot::default(),insets_changed_callback: CallbackSlot::default(),keyboard_dismiss_touch: Cell::new(None),+ back_gesture_start: Cell::new(None),keyboard_height: Cell::new(0.),mouse_position: Cell::new(Point::default()),modifiers: Cell::new(Modifiers::default()),@@ -502,6 +557,44 @@ impl IosWindowState {.with(|callback| callback(PlatformInput::Scroll(event)));}+ /// Offers a starting back gesture to GPUI, returning whether an element+ /// claimed it.+ fn begin_back_gesture(&self, recognizer: &UIGestureRecognizer) -> bool {+ let location = recognizer.locationInView(Some(&self.view));+ let start_position = Point::new(px(location.x as f32), px(location.y as f32));+ let claimed = self+ .input_callback+ .with(|callback| {+ callback(PlatformInput::BackGesture(BackGestureEvent {+ phase: BackGesturePhase::Started,+ start_position,+ progress: 0.,+ }))+ })+ .is_some_and(|result| result.default_prevented);+ self.back_gesture_start+ .set(claimed.then_some(start_position));+ claimed+ }++ /// Delivers a step of a claimed back gesture.+ fn handle_back_gesture(&self, recognizer: &UIScreenEdgePanGestureRecognizer) {+ let Some(start_position) = self.back_gesture_start.get() else {+ return;+ };+ let Some(event) = back_event(recognizer, &self.view, start_position) else {+ return;+ };+ if matches!(+ event.phase,+ BackGesturePhase::Committed | BackGesturePhase::Cancelled+ ) {+ self.back_gesture_start.set(None);+ }+ self.input_callback+ .with(|callback| callback(PlatformInput::BackGesture(event)));+ }+fn handle_keyboard_dismiss_touch(&self, event: &TouchEvent) {if self.keyboard_height.get() <= 0. {self.keyboard_dismiss_touch.set(None);@@ -580,6 +673,20 @@ impl IosWindowState {bottom: px(self.keyboard_height.get()),..Default::default()},+ corner_radii: self.display_corner_radii(),+ }+ }++ fn display_corner_radii(&self) -> Corners<Pixels> {+ if !reports_corner_radii(&self.view) {+ return Corners::default();+ }+ let radius = |corner| px(self.view.effectiveRadiusForCorner(corner) as f32);+ Corners {+ top_left: radius(UIRectCorner::TopLeft),+ top_right: radius(UIRectCorner::TopRight),+ bottom_right: radius(UIRectCorner::BottomRight),+ bottom_left: radius(UIRectCorner::BottomLeft),}}@@ -686,6 +793,11 @@ impl IosWindowState {}}+/// Whether UIKit can resolve corner configurations, which arrived in iOS 26.+fn reports_corner_radii(view: &UIView) -> bool {+ view.respondsToSelector(sel!(effectiveRadiusForCorner:))+}+impl Drop for IosWindow {fn drop(&mut self) {if let Some(platform) = self.platform.upgrade() {