Files
orca/mobile/src/session/tab-strip-scroll.ts
T
Jinjing dccea75b0e Fix active tab scrolling and editor keyboard layout on mobile (#5271)
* Improve mobile session tab scrolling and editor keyboard layout

- Auto-scroll the active session tab into view within the horizontal
  tab strip, using a new layout-aware utility with minimal scrolling.
- Use visual viewport measurements in the editor WebView to accurately
  report keyboard insets and lift floating controls above the keyboard,
  as native events can under-report covered areas.

* Fix active tab scrolling and normalize editor keyboard inset

- Ensure the active session tab is scrolled into view immediately when
  its layout finishes to prevent it from remaining hidden off-screen.
- Round, clamp, and validate WebView visualViewport bottom measurements
  to avoid rendering inconsistencies from fractional or invalid insets.
- Trigger an immediate keyboard inset report on script initialization.

* Update tabStripOffsetRef when scrolling mobile tab strip

Ensure the cached offset is updated to match the next scroll position. Without this update, subsequent scroll calculations would use stale offset values.
2026-06-12 11:09:08 -07:00

41 lines
997 B
TypeScript

export type TabStripScrollInput = {
tabX: number
tabWidth: number
viewportWidth: number
contentWidth: number
currentOffset: number
margin?: number
}
/**
* Keep active-tab reveal deterministic across async RN layout events without
* nudging the strip when the tab is already visible.
*/
export function resolveTabStripScrollOffset({
tabX,
tabWidth,
viewportWidth,
contentWidth,
currentOffset,
margin = 12
}: TabStripScrollInput): number {
const maxOffset = Math.max(0, contentWidth - viewportWidth)
if (viewportWidth <= 0) {
return currentOffset
}
const visibleStart = currentOffset
const visibleEnd = currentOffset + viewportWidth
const tabStart = tabX
const tabEnd = tabX + tabWidth
let nextOffset = currentOffset
if (tabStart < visibleStart + margin) {
nextOffset = tabStart - margin
} else if (tabEnd > visibleEnd - margin) {
nextOffset = tabEnd + margin - viewportWidth
}
return Math.min(Math.max(0, nextOffset), maxOffset)
}