Fix iOS terminal dock keyboard pinning (bars jump to mid-screen)
On iPhone, opening the software keyboard in a terminal workspace launched the shortcut toolbar and the Message composer to the middle of the screen (roughly an extra keyboard height above their correct spot, with the two bars visibly separating mid-flight), then they settled back down about a third of a second after the keyboard finished. Sometimes they never settled and stayed stranded mid-screen.
Four stacked causes, all in the terminal dock path:
- The composer's
UIHostingControllerwas the only hosting controller in the app withoutsafeAreaRegions = .container, so SwiftUI keyboard avoidance ran inside the band andsizeThatFitsmeasurements taken while the keyboard rose came back inflated by the keyboard overlap. That inflated height becamecomposerBandHeight, and the toolbar rides the band's top edge, so both bars jumped a keyboard height too high. A later clean re-measure settled them; when none arrived they stayed stuck. handleKeyboardWillChangeFrameguarded on the cached animation target instead of the on-screen position, so repeat notifications during an interrupted transition were swallowed and the dock stayed parked wherever it was.- Three animation clocks (keyboard curve, hardcoded 0.25s ease-in-out band reflow, hardcoded 0.25s
animateBottomDock) ran additively on the same layers. layoutSubviewsandsafeAreaInsetsDidChangesnapped dock frames outside any animation mid-flight.
Fix, modeled on the already-hardened agent-chat keyboard controller: a pure TerminalDockKeyboardTransitionPlanner (in CmuxMobileTerminalKit, unit-tested) decides ignore/apply/animate per notification by comparing the presentation-layer visible position against the target; the surface pins the model to the visible position and removes stale dock animations before starting each transition; every non-keyboard dock reflow joins the active keyboard animation's curve and remaining duration through one animateDockReflow helper; mid-flight bounds or safe-area changes re-pin and animate the remainder instead of snapping; the composer host opts out of SwiftUI keyboard avoidance and clamps measured band heights to 45% of the surface as a backstop; the async scheduleKeyboardHideHeightResync band-aid is replaced by a deterministic completion settle.
Verification: 106 CmuxMobileTerminalKit tests pass including 6 new planner cases covering the stuck-bar re-drive, synthesized durations for zero-duration notifications, and safe-area boundary pinning. iOS simulator build and device build compile and run; keyboard-up layout verified on the simulator with the bars flush against the keyboard top. A two-commit red/green split was not practical because the buggy logic lived in unhosted UIKit paths; the planner tests lock the new behavior instead.
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.
Summary by cubic
Fixes iOS terminal dock keyboard pinning so the toolbar and composer stay flush to the keyboard and no longer jump or get stranded mid-screen. The dock now follows keyboard transitions reliably, even during interruptions and safe-area changes.
-
Bug Fixes
- Opt out of SwiftUI keyboard avoidance in the composer host (
safeAreaRegions = .container). - Clamp composer band height to 45% of the surface to avoid inflated measurements during keyboard rise.
- Use a new
TerminalDockKeyboardTransitionPlannerto decide ignore/apply/animate from presentation-layer geometry. - Pin the dock to the visible position and remove stale animations before each transition; route all reflows through one
animateDockReflowon the active keyboard curve. - Handle zero-duration and interrupted notifications by synthesizing durations; re-pin and continue mid-flight on bounds/safe-area changes instead of snapping.
- Replace the async keyboard-hide resync with a deterministic completion settle.
- Opt out of SwiftUI keyboard avoidance in the composer host (
-
Refactors
- Added
TerminalDockKeyboardTransitionInput,TerminalDockKeyboardTransitionPlan, andTerminalDockKeyboardTransitionPlannerinCmuxMobileTerminalKit, with unit tests for stuck-bar re-drive, zero-duration synthesis, and safe-area boundary pinning. - Extended
TerminalKeyboardHeightAnimationto track target overlap, animation options, and end timestamp for shared dock timing.
- Added
Summary by CodeRabbit
- Bug Fixes
- Improved keyboard transitions to reduce jumps, flicker, and unnecessary layout changes.
- Kept the terminal dock correctly positioned while the keyboard appears, disappears, or changes size.
- Improved handling of interrupted keyboard animations and varying transition durations.
- Prevented the composer from occupying more than 45% of the available terminal surface.
- Improved safe-area and keyboard geometry handling for the composer field.