mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-25 01:30:06 +08:00
iOS keyboard: the globe opens the list where Apple's keyboard is split, so the host doesn't crash (#2340)
TestFlight build 121 (048a4751), iPhone Duo, iOS 27.2.1: tapping Hex's globe killed
the app being typed in (here the Hex app) with
"-[__NSArrayM objectAtIndex:]: index 42 beyond bounds [0 .. 41]".
Symbolicated against the iPhone19,4 24B91034 dyld cache, the crash is entirely in the
host's UIKit: the extension's "next keyboard" output ->
-[_UIKeyboardStateManager setInputModeToNextInPreferredListWithExecutionContext:] ->
_setKeyboardInputMode:...updateIndicator:YES -> reinitializeAfterInputModeSwitch: ->
-[UIKeyboardImpl updateInputModeIndicatorOnSingleKeyOnly:preserveIfPossible:] ->
-[UIKeyboardLayoutStar activationIndicatorView]. That method builds the language
indicator only when Apple's keyplane has its own globe, and for a split keyplane walks
the bottom row's keys by frame; when the keys aren't laid out yet (the first switch into
Apple's keyboard in a host that opened with Hex) it reads keys[count] and throws. On an
iPad mini 27.2 simulator with Apple's split keyboard, the first call sees every key at
{0,0,0,0} but the bottom row; the iPad's geometry happens to stay in bounds, the Duo's
split keyboard (Apple splits it unfolded and upright) evidently does not.
Picking a keyboard from the list goes through
_setKeyboardInputMode:...updateIndicator:NO and never reaches that code (checked with
breakpoints on the same simulator). So where Apple's keyboard is split
(KeyboardPosture.splitsKeyboard, the Duo unfolded and upright), the globe now holds back
the lift of a touch that stayed on the key: UIKit's own 0.2 s hold then opens the list
instead of switching to the next keyboard. Holds, slides up and slide-and-pick still go
to UIKit unchanged. Everywhere else (every iPhone, the Duo folded or turned, every iPad)
the globe behaves exactly as before.
Wiring: the globe still hands this control's real UIEvents to
handleInputModeList(from:with:) for .allTouchEvents, as Apple documents; it now does so
from FullKeyboardView (globeTouch) instead of targeting the controller directly, which
is what lets it drop that one lift.
Verified (Mac Studio, iOS 27.2 simulators):
- xcodebuild test: 758 tests, 0 failures (layout tests untouched), plus
testTheGlobePassesItsTouchesToUIKit in FullKeyboardEngineTests.
- iPad mini, Apple's keyboard split, the split rule forced on by a diagnostic build:
a tap opens the list (no next-keyboard switch, no indicator call), picking English
(US) switches to Apple's split keyboard, host alive.
- Not verified on a real Duo: the Duo simulator takes no touches and can't be unfolded
(powering its inner display crashes SpringBoard), so the fix is unconfirmed there.
This commit is contained in:
@@ -2833,6 +2833,27 @@ final class FullKeyboardEngineTests: XCTestCase {
|
||||
XCTAssertEqual(controller.reportedLanguages, ["it-IT", "en-US", "it-IT"], "each change sent once")
|
||||
}
|
||||
|
||||
/// The globe hands its own touches to UIKit's `handleInputModeList(from:with:)` (Apple's
|
||||
/// documented wiring). Where Apple's keyboard is split (the Duo unfolded), a tap's lift isn't
|
||||
/// passed on, so the list opens instead of UIKit's switch to the next keyboard, which can end
|
||||
/// the app being typed in there (TestFlight build 121).
|
||||
func testTheGlobePassesItsTouchesToUIKit() {
|
||||
let view = FullKeyboardView(model: KeyboardViewModel(), target: target)
|
||||
view.hostController = RecordingInputController()
|
||||
for event: UIControl.Event in [.touchDown, .touchDragInside, .touchDragOutside, .touchUpInside, .touchUpOutside, .touchCancel] {
|
||||
XCTAssertEqual(view.globeButton.actions(forTarget: view, forControlEvent: event), ["globeTouch:with:"])
|
||||
}
|
||||
for phase: UITouch.Phase in [.began, .moved, .ended, .cancelled] {
|
||||
XCTAssertTrue(FullKeyboardView.passesGlobeTouch(phase: phase, onKey: true, leftKey: false, appleKeyboardSplits: false))
|
||||
}
|
||||
XCTAssertFalse(FullKeyboardView.passesGlobeTouch(phase: .ended, onKey: true, leftKey: false, appleKeyboardSplits: true), "a tap")
|
||||
XCTAssertTrue(FullKeyboardView.passesGlobeTouch(phase: .began, onKey: true, leftKey: false, appleKeyboardSplits: true))
|
||||
XCTAssertTrue(FullKeyboardView.passesGlobeTouch(phase: .moved, onKey: false, leftKey: true, appleKeyboardSplits: true))
|
||||
XCTAssertTrue(FullKeyboardView.passesGlobeTouch(phase: .ended, onKey: false, leftKey: true, appleKeyboardSplits: true), "lifting over the list picks")
|
||||
XCTAssertTrue(FullKeyboardView.passesGlobeTouch(phase: .ended, onKey: true, leftKey: true, appleKeyboardSplits: true))
|
||||
XCTAssertTrue(FullKeyboardView.passesGlobeTouch(phase: .cancelled, onKey: true, leftKey: false, appleKeyboardSplits: true))
|
||||
}
|
||||
|
||||
func testOnlyTheEnglishAndSpanishLayoutsSwipe() {
|
||||
let view = FullKeyboardView(model: KeyboardViewModel(), target: FixtureTextTarget())
|
||||
view.swipeOverride = true
|
||||
|
||||
@@ -57,6 +57,8 @@ final class FullKeyboardView: UIView {
|
||||
private var barHoldTouch: UITouch?
|
||||
private var barHoldWork: DispatchWorkItem?
|
||||
private var lastDictation: DictationUndo?
|
||||
/// The globe's touch went off the key before lifting (`globeTouch`).
|
||||
private var globeTouchLeftKey = false
|
||||
/// The model's stage last seen, for a selection's dictation ending
|
||||
/// (`FullKeyboardView+Selection`).
|
||||
var lastStagePhase: KeyboardViewModel.StagePhase?
|
||||
@@ -1410,14 +1412,36 @@ final class FullKeyboardView: UIView {
|
||||
}
|
||||
}
|
||||
|
||||
/// The globe's touches go to UIKit's `handleInputModeList(from:with:)` as this control's
|
||||
/// real events, as Apple documents: a tap switches to the next keyboard, a hold (0.2 s) or a
|
||||
/// slide up opens the list, and lifting over the list picks that keyboard.
|
||||
private func configureGlobe() {
|
||||
globeButton.removeTarget(nil, action: nil, for: .allEvents)
|
||||
if let controller = hostController {
|
||||
globeButton.addTarget(
|
||||
controller,
|
||||
action: #selector(UIInputViewController.handleInputModeList(from:with:)),
|
||||
for: .allTouchEvents
|
||||
)
|
||||
guard hostController != nil else { return }
|
||||
globeButton.addTarget(self, action: #selector(globeTouch(_:with:)), for: .allTouchEvents)
|
||||
}
|
||||
|
||||
@objc private func globeTouch(_ sender: UIButton, with event: UIEvent) {
|
||||
guard let controller = hostController else { return }
|
||||
if let touch = event.touches(for: sender)?.first {
|
||||
let onKey = sender.bounds.contains(touch.location(in: sender))
|
||||
if touch.phase == .began { globeTouchLeftKey = false }
|
||||
if touch.phase == .moved, !onKey { globeTouchLeftKey = true }
|
||||
guard Self.passesGlobeTouch(
|
||||
phase: touch.phase, onKey: onKey, leftKey: globeTouchLeftKey,
|
||||
appleKeyboardSplits: engine.posture.splitsKeyboard
|
||||
) else { return }
|
||||
}
|
||||
controller.handleInputModeList(from: sender, with: event)
|
||||
}
|
||||
|
||||
/// Where Apple's keyboard is split (the Duo unfolded and upright), a lift on the globe that
|
||||
/// never left it isn't passed on, so UIKit's hold opens the list instead of switching to the
|
||||
/// next keyboard. iOS 27.2's switch to the next keyboard can end the app being typed in there
|
||||
/// (TestFlight build 121, iPhone Duo: `-[UIKeyboardLayoutStar activationIndicatorView]` reads
|
||||
/// one key past the end of a split keyboard not laid out yet, to show its language); a pick
|
||||
/// from the list doesn't show that indicator.
|
||||
static func passesGlobeTouch(phase: UITouch.Phase, onKey: Bool, leftKey: Bool, appleKeyboardSplits: Bool) -> Bool {
|
||||
!(appleKeyboardSplits && phase == .ended && onKey && !leftKey)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user