native: the hosted title and keyboard bar take no safe-area insets
Fable on #180 (4). The large title's hosting controller sits inside the text view and scrolls under the bar; the keyboard bar's sits on the screen's bottom edge, over the home indicator, when a hardware keyboard is connected. Both took UIKit's safe-area insets, which SwiftUI turns into padding inside them. `safeAreaRegions = []` on both: their frames are their layout. Test: PhoneDocumentTests.testTheHostedChromeIgnoresTheSafeArea (failed before on both). A behavioural check (SwiftUI's element positions in the bar on the bottom edge) is not available in a unit test, and the live hardware-keyboard case (Simulator ▸ I/O ▸ Keyboard) was not exercised: it is a Simulator.app menu, and the shared simulator is not this session's to reconfigure.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+24
−0
native/apple/Sources/DocsKit/DocsPhoneFormat.swift+7 −0native/apple/Sources/DocsKit/DocsPhoneHeader.swift+3 −0native/apple/Tests/DocsKitTests/PhoneDocumentTests.swift+14 −0
diff --git a/native/apple/Sources/DocsKit/DocsPhoneFormat.swift b/native/apple/Sources/DocsKit/DocsPhoneFormat.swift| index 08d5807..1840e23 100644 |
| --- a/native/apple/Sources/DocsKit/DocsPhoneFormat.swift |
| +++ b/native/apple/Sources/DocsKit/DocsPhoneFormat.swift |
| @@ -24,6 +24,9 @@ import UIKit |
| host.view.backgroundColor = .clear |
| host.view.translatesAutoresizingMaskIntoConstraints = false |
| host.sizingOptions = [.intrinsicContentSize] |
| + // With a hardware keyboard the bar sits on the bottom edge, over the |
| + // home indicator: the screen's inset is not the bar's to pad. |
| + host.safeAreaRegions = [] |
| input.addSubview(host.view) |
| NSLayoutConstraint.activate([ |
| host.view.leadingAnchor.constraint(equalTo: input.leadingAnchor), |
| @@ -34,6 +37,10 @@ import UIKit |
| objc_setAssociatedObject(input, &DocsPhoneEditorChrome.hostKey, host, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) |
| return input |
| } |
| + /// The bar's hosting controller (tests). |
| + static func host(of bar: UIView) -> UIHostingController<DocsKeyboardBar>? { |
| + objc_getAssociatedObject(bar, &hostKey) as? UIHostingController<DocsKeyboardBar> |
| + } |
| nonisolated(unsafe) private static var hostKey = 0 |
| } |
diff --git a/native/apple/Sources/DocsKit/DocsPhoneHeader.swift b/native/apple/Sources/DocsKit/DocsPhoneHeader.swift| index c9baa21..1f4bc24 100644 |
| --- a/native/apple/Sources/DocsKit/DocsPhoneHeader.swift |
| +++ b/native/apple/Sources/DocsKit/DocsPhoneHeader.swift |
| @@ -109,6 +109,9 @@ import UIKit |
| .onGeometryChange(for: CGFloat.self) { $0.size.height } action: { report?($0) }) |
| controller.view.backgroundColor = .clear |
| controller.sizingOptions = [] |
| + // It scrolls with the text, under the bar: the text view's frame is |
| + // its layout, not the screen's safe area. |
| + controller.safeAreaRegions = [] |
| report = { [weak self] height in self?.heightChanged?(height) } |
| } |
| var view: UIView { controller.view } |
diff --git a/native/apple/Tests/DocsKitTests/PhoneDocumentTests.swift b/native/apple/Tests/DocsKitTests/PhoneDocumentTests.swift| index 4f4894c..7a62847 100644 |
| --- a/native/apple/Tests/DocsKitTests/PhoneDocumentTests.swift |
| +++ b/native/apple/Tests/DocsKitTests/PhoneDocumentTests.swift |
| @@ -66,6 +66,20 @@ import XCTest |
| XCTAssertEqual(text.contentOffset.y, offset.y, accuracy: 0.5, "nor did the scroll") |
| } |
| + /// The hosted chrome lays itself out without the window's safe area |
| + /// (Fable on #180): the large title scrolls under the bar inside the |
| + /// text view, and the keyboard bar sits on the bottom edge over the home |
| + /// indicator when a hardware keyboard is connected. Neither is to be |
| + /// padded by insets that belong to the screen. |
| + func testTheHostedChromeIgnoresTheSafeArea() async throws { |
| + let (text, _, _) = try await open() |
| + let header = try XCTUnwrap(text.header) |
| + XCTAssertEqual(header.controller.safeAreaRegions, [], "the large title") |
| + let bar = try XCTUnwrap(text.inputAccessoryView) |
| + let host = try XCTUnwrap(DocsPhoneEditorChrome.host(of: bar)) |
| + XCTAssertEqual(host.safeAreaRegions, [], "the keyboard bar") |
| + } |
| + |
| /// A text view the surface attaches while the Format sheet is open (the |
| /// editor built again: a new `editorIdentity`) gets the sheet's state: |
| /// no keyboard, and the text clear of the sheet (Fable on #180). |