Files
orca/mobile/src/components/MobileWorkspaceNameInput.tsx
T
Jinjing a459100d87 Introduce MobileWorkspaceNameInput with delayed auto-focus (#5968)
- Delays input focus by 220ms to ensure animating bottom drawers settle before the soft keyboard is requested, improving focus reliability on mobile.
- Replaces standard TextInputs with this component in tasks workspace creation and the NewWorktreeModal.
2026-06-21 23:51:00 -07:00

43 lines
1.0 KiB
TypeScript

import { useEffect, useRef } from 'react'
import { TextInput, type TextInputProps } from 'react-native'
const MOBILE_WORKSPACE_NAME_FOCUS_DELAY_MS = 220
type MobileWorkspaceNameInputProps = TextInputProps & {
shouldAutoFocus: boolean
focusKey?: unknown
}
export function MobileWorkspaceNameInput({
shouldAutoFocus,
focusKey,
...props
}: MobileWorkspaceNameInputProps) {
const inputRef = useRef<TextInput>(null)
useEffect(() => {
if (!shouldAutoFocus) {
return
}
// Why: bottom drawers animate in before the field is visually settled;
// focusing after the animation makes mobile soft keyboards appear reliably.
const timeout = setTimeout(() => {
inputRef.current?.focus()
}, MOBILE_WORKSPACE_NAME_FOCUS_DELAY_MS)
return () => clearTimeout(timeout)
}, [focusKey, shouldAutoFocus])
return (
<TextInput
ref={inputRef}
placeholder="Workspace name"
autoCapitalize="none"
autoCorrect={false}
showSoftInputOnFocus
{...props}
/>
)
}