feat(mobile): draw the tab bar as the strip's square cells

The rounded pill and round buttons read as a different control from the
strip people know. The open tab is now the strip's raised, underlined cell
from the screen edge, with the count and + as square cells in the same
row, which also gives them 46x44 pt targets.
This commit is contained in:
Kelvin Amoaba
2026-11-10 04:49:48 +00:00
parent 6ec46d59c4
commit dfcbd0f0c3
6 changed files with 140 additions and 123 deletions
+4 -15
View File
@@ -1,4 +1,4 @@
import type { ComponentType, ReactNode, Ref } from 'react'
import type { ComponentType, Ref } from 'react'
import { Pressable, type View } from 'react-native'
import { colors, feedback, radii } from '../../theme/mobile-theme'
import { themedStyleSheet } from '../../theme/themed-styles'
@@ -10,25 +10,19 @@ type IconProps = { size?: number; color?: string; strokeWidth?: number }
type NavBarButtonProps = {
ref?: Ref<View>
icon: ComponentType<IconProps>
accessibilityLabel: string
accessibilityHint?: string
onPress: () => void
/** The screen or panel this button opens is showing. */
active?: boolean
disabled?: boolean
} & (
| { icon: ComponentType<IconProps>; children?: never }
/** Drawn in place of an icon, e.g. a tab count. */
| { icon?: never; children: ReactNode }
)
}
// A round top-bar button; the bar floats over content like the composer, so its buttons are round too.
export function NavBarButton({
ref,
icon: Icon,
children,
accessibilityLabel,
accessibilityHint,
onPress,
active = false,
disabled = false
@@ -48,14 +42,9 @@ export function NavBarButton({
hitSlop={4}
accessibilityRole="button"
accessibilityLabel={accessibilityLabel}
accessibilityHint={accessibilityHint}
accessibilityState={{ disabled, selected: active }}
>
{Icon ? (
<Icon size={18} color={active ? colors.bgBase : colors.textPrimary} strokeWidth={2.1} />
) : (
children
)}
<Icon size={18} color={active ? colors.bgBase : colors.textPrimary} strokeWidth={2.1} />
</Pressable>
)
}
+9 -9
View File
@@ -2925,15 +2925,6 @@
"stop": "Stop",
"yes": "Yes"
},
"tabPill": {
"oneTab": "1 tab",
"tabCount": "{{count}} tabs",
"anotherNeedsYou": "another tab needs you",
"hint": "Shows all tabs",
"next": "Next tab",
"previous": "Previous tab",
"actionsHint": "Shows actions for this tab"
},
"tabsSheet": {
"needsYou": "Needs you",
"working": "Working",
@@ -2947,6 +2938,15 @@
"file": "File",
"chat": "Chat",
"terminal": "Terminal"
},
"tabBar": {
"oneTab": "1 tab",
"tabCount": "{{count}} tabs",
"anotherNeedsYou": "another tab needs you",
"actionsHint": "Shows actions for this tab",
"next": "Next tab",
"previous": "Previous tab",
"hint": "Shows all tabs"
}
},
"chat": {
+3 -3
View File
@@ -6,7 +6,7 @@ import { NavBar, NavBarRefreshLine } from '../components/nav-bar/NavBar'
import { useRefreshHint } from '../query/refresh-hint'
import { NavBarButton } from '../components/nav-bar/NavBarButton'
import { MobileSessionHeaderMoreMenu } from './MobileSessionHeaderMoreMenu'
import { MobileSessionTabPill } from './tabs/MobileSessionTabPill'
import { MobileSessionTabBar } from './tabs/MobileSessionTabBar'
import { MobileSessionTitleBlock } from './MobileSessionTitleBlock'
import type { SessionTitleCard } from './tabs/use-session-title-card'
import { styles } from './mobile-session-styles'
@@ -58,11 +58,11 @@ export function MobileSessionHeader({
// Why: a sideways phone is ~390pt tall, so the tabs share the top bar instead of taking a second row.
const hasTabs = visibleTabs.length > 0
const tabsInTopBar = (layout.isLandscapePhone || sideRail) && hasTabs
// Bar buttons otherwise leave the tab pill too narrow to read on a narrow header.
// Bar buttons otherwise leave the tab bar too narrow to read on a narrow header.
const actionsCollapsed = tabsInTopBar && (headerWidth ?? layout.width) < 600
const sourceControlInBar = !isFloatingWorkspaceRoute && !actionsCollapsed
const tabStrip = hasTabs ? (
<MobileSessionTabPill
<MobileSessionTabBar
controller={controller}
inTopBar={tabsInTopBar}
actionsCollapsed={actionsCollapsed}
@@ -14,14 +14,13 @@ import { triggerMediumImpact, triggerSelection } from '../../platform/haptics'
import { useMobileTranslation } from '../../i18n/use-mobile-translation'
import { AgentStateDot } from '../../components/AgentStateDot'
import { ArrivalFade } from '../../components/ArrivalFade'
import { NavBarButton } from '../../components/nav-bar/NavBarButton'
import { useDrawerReducedMotion } from '../../components/bottom-drawer/bottom-drawer-constants'
import { SHEET_CURVE } from '../../components/sheet-motion-values'
import { useReducedMotionEnabled } from '../../platform/use-reduced-motion'
import { useKeyboardPersistingTaps } from '../../platform/keyboard-persisting-taps'
import { useNow } from '../../hooks/use-now'
import { agentStateLabel, type AgentDotState } from '../../worktree/agent-row-display'
import { colors, radii, spacing } from '../../theme/mobile-theme'
import { colors, feedback, radii, spacing } from '../../theme/mobile-theme'
import { themedStyleSheet } from '../../theme/themed-styles'
import { useMobileColorScheme } from '../../theme/use-mobile-color-scheme'
import { buildMobileSessionTabRow, type MobileSessionTabRow } from './mobile-session-tab-rows'
@@ -29,26 +28,25 @@ import { MobileSessionTabMark } from './MobileSessionTabMark'
import { MobileSessionTabsSheet } from './MobileSessionTabsSheet'
import type { MobileSessionController } from '../use-mobile-session-controller'
const PILL_HEIGHT = 34
const SWIPE_SETTLE_MS = 250
// A tab arriving from the side starts this far out, as a share of the pill's width.
// A tab arriving from the side starts this far out, as a share of the tab cell's width.
const SWIPE_ENTRY_SHARE = 0.4
const FLICK_VELOCITY = 600
// With no tab on that side, the pill gives only this share of the drag.
// With no tab on that side, the tab gives only this share of the drag.
const EDGE_RESISTANCE = 0.25
const DRAG_CLICK_WINDOW_MS = 400
// A tab drawn before it had any agent state (from the phone's store) fades its dot in when one lands.
function TabPillDot({ tabId, state }: { tabId: string; state: AgentDotState | undefined }) {
function TabBarDot({ tabId, state }: { tabId: string; state: AgentDotState | undefined }) {
const [startedEmpty] = useState({ tabId, empty: state === undefined })
if (startedEmpty.tabId === tabId && startedEmpty.empty) {
return <ArrivingTabPillDot state={state} />
return <ArrivingTabBarDot state={state} />
}
return state && state !== 'idle' ? <AgentStateDot state={state} /> : null
}
// Mounted with the bare tab, so the motion preference is read before the dot arrives.
function ArrivingTabPillDot({ state }: { state: AgentDotState | undefined }) {
function ArrivingTabBarDot({ state }: { state: AgentDotState | undefined }) {
const reducedMotion = useReducedMotionEnabled()
if (!state || state === 'idle') {
return null
@@ -60,8 +58,8 @@ function ArrivingTabPillDot({ state }: { state: AgentDotState | undefined }) {
)
}
/** The tab you're in as one pill: tap for every tab, swipe for the next one, + for a new one. */
export function MobileSessionTabPill({
/** The tab you're in as one cell: tap for its actions, swipe for the next one; the count shows every tab, + adds one. */
export function MobileSessionTabBar({
controller,
inTopBar,
actionsCollapsed = false
@@ -82,7 +80,7 @@ export function MobileSessionTabPill({
visibleTabs,
terminals
} = controller
// Why: the first tap must reach the pill with the keyboard open instead of only dismissing it (#5106).
// Why: the first tap must reach the bar with the keyboard open instead of only dismissing it (#5106).
const keepsKeyboard = useKeyboardPersistingTaps('handled')
const now = useNow(60_000)
const rows = useMemo(
@@ -101,7 +99,7 @@ export function MobileSessionTabPill({
const reducedMotion = useDrawerReducedMotion()
const offset = useSharedValue(0)
const width = useSharedValue(0)
// On the web, releasing a mouse drag also clicks the pill.
// On the web, releasing a mouse drag also clicks the tab.
const dragEndedAtRef = useRef(0)
const settle = (to: number) =>
withTiming(
@@ -145,7 +143,7 @@ export function MobileSessionTabPill({
offset.value = settle(0)
})
// Web has no worklet plugin; mapper hooks need this explicit dependency list.
const pillStyle = useAnimatedStyle(
const contentStyle = useAnimatedStyle(
() => ({
transform: [{ translateX: offset.value }],
opacity: 1 - Math.min(Math.abs(offset.value) / Math.max(width.value, 1), 1) * 0.6
@@ -156,14 +154,14 @@ export function MobileSessionTabPill({
const status = active?.dotState && active.dotState !== 'idle' ? active.dotState : undefined
const countLabel =
rows.length === 1
? t('session.tabPill.oneTab', '1 tab')
: t('session.tabPill.tabCount', '{{count}} tabs', { count: rows.length })
const pillLabel = [active?.title, status ? agentStateLabel(status) : null]
? t('session.tabBar.oneTab', '1 tab')
: t('session.tabBar.tabCount', '{{count}} tabs', { count: rows.length })
const tabLabel = [active?.title, status ? agentStateLabel(status) : null]
.filter(Boolean)
.join(', ')
const countAccessibilityLabel = [
countLabel,
othersNeedYou ? t('session.tabPill.anotherNeedsYou', 'another tab needs you') : null
othersNeedYou ? t('session.tabBar.anotherNeedsYou', 'another tab needs you') : null
]
.filter(Boolean)
.join(', ')
@@ -178,77 +176,91 @@ export function MobileSessionTabPill({
return (
<View ref={keepsKeyboard} style={inTopBar ? styles.barInTopBar : styles.bar}>
<View
style={styles.track}
onLayout={(event) => {
width.value = event.nativeEvent.layout.width
}}
>
{/* pan-y keeps vertical touches with the page on the web. */}
<GestureDetector gesture={pan} touchAction="pan-y">
<Animated.View style={[styles.pillFrame, pillStyle]}>
<Pressable
style={({ pressed }) => [styles.pill, pressed && styles.pillPressed]}
onPress={openTabActions}
onLongPress={() => {
triggerMediumImpact()
openTabActions()
}}
delayLongPress={400}
disabled={!active}
accessibilityRole="button"
accessibilityLabel={pillLabel || countLabel}
accessibilityHint={t('session.tabPill.actionsHint', 'Shows actions for this tab')}
accessibilityActions={[
...(next
? [{ name: 'nextTab', label: t('session.tabPill.next', 'Next tab') }]
: []),
...(previous
? [{ name: 'previousTab', label: t('session.tabPill.previous', 'Previous tab') }]
: [])
]}
onAccessibilityAction={(event) => {
const name = event.nativeEvent.actionName
if (name === 'nextTab') {
step(next, -1)
} else if (name === 'previousTab') {
step(previous, 1)
}
}}
>
{/* pan-y keeps vertical touches with the page on the web. */}
<GestureDetector gesture={pan} touchAction="pan-y">
<View
style={styles.tabCell}
onLayout={(event) => {
width.value = event.nativeEvent.layout.width
}}
>
<Pressable
style={({ pressed }) => [styles.tabPress, pressed && styles.cellPressed]}
onPress={openTabActions}
onLongPress={() => {
triggerMediumImpact()
openTabActions()
}}
delayLongPress={400}
disabled={!active}
accessibilityRole="button"
accessibilityLabel={tabLabel || countLabel}
accessibilityHint={t('session.tabBar.actionsHint', 'Shows actions for this tab')}
accessibilityActions={[
...(next ? [{ name: 'nextTab', label: t('session.tabBar.next', 'Next tab') }] : []),
...(previous
? [{ name: 'previousTab', label: t('session.tabBar.previous', 'Previous tab') }]
: [])
]}
onAccessibilityAction={(event) => {
const name = event.nativeEvent.actionName
if (name === 'nextTab') {
step(next, -1)
} else if (name === 'previousTab') {
step(previous, 1)
}
}}
>
{/* Only the contents slide, so the cell stays flush with the screen edge. */}
<Animated.View style={[styles.tabContent, contentStyle]}>
{active ? (
<>
<TabPillDot tabId={active.tab.id} state={active.dotState} />
<TabBarDot tabId={active.tab.id} state={active.dotState} />
<View style={styles.mark}>
<MobileSessionTabMark row={active} size={15} />
<MobileSessionTabMark row={active} size={14} />
</View>
</>
) : null}
<Text style={styles.title} numberOfLines={1}>
{active?.title ?? countLabel}
</Text>
</Pressable>
</Animated.View>
</GestureDetector>
</View>
{/* Lined up under the header's buttons; a collapsed bar's + lives in the header's ⋯ menu. */}
<NavBarButton
</Animated.View>
</Pressable>
</View>
</GestureDetector>
<Pressable
style={({ pressed }) => [
styles.sideCell,
actionsCollapsed && styles.lastCell,
pressed && styles.cellPressed
]}
onPress={() => setSheetOpen(true)}
accessibilityRole="button"
accessibilityLabel={countAccessibilityLabel}
accessibilityHint={t('session.tabPill.hint', 'Shows all tabs')}
accessibilityHint={t('session.tabBar.hint', 'Shows all tabs')}
>
<View style={styles.countBox}>
<Text style={styles.countText}>{rows.length}</Text>
</View>
{othersNeedYou ? <View style={styles.alert} /> : null}
</NavBarButton>
</Pressable>
{/* A collapsed bar's + lives in the header's ⋯ menu. */}
{!actionsCollapsed ? (
<NavBarButton
<Pressable
style={({ pressed }) => [
styles.sideCell,
styles.lastCell,
pressed && styles.cellPressed,
createDisabled && styles.cellDisabled
]}
disabled={createDisabled}
onPress={handleOpenNewTab}
accessibilityRole="button"
accessibilityLabel={t('session.tabStrip.newTab', 'New tab')}
icon={Plus}
/>
accessibilityState={{ disabled: createDisabled }}
>
<Plus size={18} color={colors.textPrimary} strokeWidth={2.2} />
</Pressable>
) : null}
<MobileSessionTabsSheet
controller={controller}
@@ -261,46 +273,62 @@ export function MobileSessionTabPill({
}
const styles = themedStyleSheet(() => ({
// The right inset matches the nav bar's, so the + lines up with the ⋯ above it.
bar: {
height: 44,
flexDirection: 'row',
alignItems: 'center',
gap: spacing.sm,
paddingHorizontal: spacing.md,
alignItems: 'stretch',
borderTopWidth: 1,
borderTopColor: colors.borderSubtle
},
// Cancels the top bar's vertical padding so the cells run the bar's full height.
barInTopBar: {
flex: 1,
minWidth: 0,
flexDirection: 'row',
alignItems: 'center',
gap: spacing.sm,
marginLeft: spacing.sm
alignItems: 'stretch',
alignSelf: 'stretch',
marginVertical: -spacing.xs,
marginLeft: spacing.md,
borderLeftWidth: 1,
borderLeftColor: colors.borderSubtle
},
track: { flex: 1, minWidth: 0 },
pillFrame: { width: '100%' },
pill: {
height: PILL_HEIGHT,
flexDirection: 'row',
alignItems: 'center',
gap: 7,
paddingLeft: 11,
paddingRight: spacing.md,
borderRadius: radii.control,
backgroundColor: colors.bgRaised
// The open tab, drawn like the strip's active tab: raised, with a line under it.
tabCell: {
flex: 1,
minWidth: 0,
backgroundColor: colors.bgRaised,
borderBottomWidth: 2,
borderBottomColor: colors.textSecondary,
borderRightWidth: 1,
borderRightColor: colors.borderSubtle,
overflow: 'hidden'
},
pillPressed: { backgroundColor: colors.translucentFill },
tabPress: {
flex: 1,
justifyContent: 'center',
paddingLeft: spacing.lg,
paddingRight: spacing.sm
},
tabContent: { flexDirection: 'row', alignItems: 'center', gap: 6 },
// Keeps web SVGs from shrinking before the title ellipsizes.
mark: { flexShrink: 0 },
title: {
flex: 1,
flexShrink: 1,
minWidth: 0,
fontSize: 15,
fontSize: 14,
fontWeight: '600',
color: colors.textPrimary
},
sideCell: {
width: 46,
alignItems: 'center',
justifyContent: 'center',
borderRightWidth: 1,
borderRightColor: colors.borderSubtle
},
lastCell: { borderRightWidth: 0 },
cellPressed: { backgroundColor: colors.translucentFill },
cellDisabled: { opacity: feedback.disabledOpacity },
countBox: {
minWidth: 19,
height: 19,
@@ -317,16 +345,16 @@ const styles = themedStyleSheet(() => ({
color: colors.textPrimary,
fontVariant: ['tabular-nums']
},
// Another tab needs you: a red dot on the button's corner, ringed in its colour.
// Another tab needs you: a red dot on the count's corner, ringed in the bar's colour.
alert: {
position: 'absolute',
top: 5,
right: 6,
top: 8,
right: 9,
width: 9,
height: 9,
borderRadius: radii.pill,
backgroundColor: colors.statusRed,
borderWidth: 2,
borderColor: colors.bgRaised
borderColor: colors.bgPanel
}
}))
@@ -62,8 +62,8 @@ export function MobileSessionTabsSheet({
}
const title =
rows.length === 1
? t('session.tabPill.oneTab', '1 tab')
: t('session.tabPill.tabCount', '{{count}} tabs', { count: rows.length })
? t('session.tabBar.oneTab', '1 tab')
: t('session.tabBar.tabCount', '{{count}} tabs', { count: rows.length })
const renderRow = (row: MobileSessionTabRow) => {
const current = row.tab.id === activeSessionTabId
@@ -76,7 +76,7 @@ export function useMobileSessionPresentation(scope: MobileSessionBulkCloseModel)
presentedConnState === 'connected'
? showLoadingState && visibleTabs.length === 0
? t('session.presentation.loadingTabs', 'Loading tabs')
: // The tab count lives on the tab pill, so the header names the branch instead.
: // The tab count lives in the tab bar, so the header names the branch instead.
(scope.worktreeBranch ?? MOBILE_SESSION_STATUS_LABELS.connected)
: showConnectionRetry
? t('session.presentation.tapToRetry', '{{status}} — tap to retry', {