diff --git a/mobile/app/h/[hostId]/index.tsx b/mobile/app/h/[hostId]/index.tsx index 7fb6a1f6e..d613bff45 100644 --- a/mobile/app/h/[hostId]/index.tsx +++ b/mobile/app/h/[hostId]/index.tsx @@ -1,13 +1,5 @@ import { useState, useEffect, useCallback, useMemo, useRef } from 'react' -import { - View, - Text, - StyleSheet, - SectionList, - Pressable, - ActivityIndicator, - TextInput -} from 'react-native' +import { View, Text, StyleSheet, SectionList, Pressable, ActivityIndicator } from 'react-native' import { SafeAreaView, useSafeAreaInsets } from 'react-native-safe-area-context' import { useFocusEffect, useLocalSearchParams, usePathname, useRouter } from 'expo-router' import { @@ -56,6 +48,7 @@ import { ConfirmModal } from '../../../src/components/ConfirmModal' import { BottomDrawer } from '../../../src/components/BottomDrawer' import { ProtocolBlockScreen } from '../../../src/components/ProtocolBlockScreen' import { AuthFailedBanner } from '../../../src/components/AuthFailedBanner' +import { MobileSearchField } from '../../../src/components/MobileSearchField' import { WorkspaceDetailPlaceholder } from '../../../src/components/WorkspaceDetailPlaceholder' import { getCachedWorktrees } from '../../../src/cache/worktree-cache' import { setCachedRepos } from '../../../src/cache/repo-cache' @@ -1134,22 +1127,16 @@ export function HostScreen({ {/* Search bar */} {showSearch && ( - - - {search.length > 0 && ( - setSearch('')}> - - - )} )} @@ -1181,6 +1168,9 @@ export function HostScreen({ sections={sections} keyExtractor={(w) => w.sectionListKey ?? w.worktreeId} stickySectionHeadersEnabled={false} + // Why: keep the search IME up while tapping clear / scrolling results. + keyboardShouldPersistTaps="handled" + keyboardDismissMode="on-drag" onScrollToIndexFailed={onScrollToIndexFailed} // Why: edge-to-edge — the list scrolls under the system nav bar // while reserving insets.bottom keeps the last worktree row reachable @@ -1615,21 +1605,12 @@ const styles = StyleSheet.create({ padding: spacing.xs }, searchBar: { - flexDirection: 'row', - alignItems: 'center', paddingHorizontal: spacing.md, - paddingVertical: spacing.xs + 2, - gap: spacing.sm, - borderBottomWidth: 1, + paddingVertical: spacing.sm, + borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: colors.borderSubtle, backgroundColor: colors.bgPanel }, - searchInput: { - flex: 1, - color: colors.textPrimary, - fontSize: 13, - paddingVertical: 2 - }, centered: { flex: 1, alignItems: 'center', diff --git a/mobile/app/h/[hostId]/tasks.tsx b/mobile/app/h/[hostId]/tasks.tsx index 08f69b497..fea23f017 100644 --- a/mobile/app/h/[hostId]/tasks.tsx +++ b/mobile/app/h/[hostId]/tasks.tsx @@ -29,7 +29,6 @@ import { Pencil, Plus, RefreshCw, - Search, Send, X } from 'lucide-react-native' @@ -48,6 +47,7 @@ import { ConfirmModal } from '../../../src/components/ConfirmModal' import { MobileMarkdown } from '../../../src/components/MobileMarkdown' import { MobileAgentIcon } from '../../../src/components/MobileAgentIcon' import { MobileWorkspaceNameInput } from '../../../src/components/MobileWorkspaceNameInput' +import { MobileSearchField } from '../../../src/components/MobileSearchField' import { MobileSyntaxSegments } from '../../../src/components/MobileSyntaxSegments' import { PickerModal, type PickerOption } from '../../../src/components/PickerModal' import { TaskProviderLogo } from '../../../src/components/TaskProviderLogo' @@ -8668,6 +8668,7 @@ export default function MobileTasksScreen() { : provider === 'gitlab' ? 'No GitLab tasks' : 'No Linear tasks' + const isGithubProjectSearch = provider === 'github' && githubMode === 'project' return ( @@ -9048,31 +9049,33 @@ export default function MobileTasksScreen() { {provider === 'gitlab' && gitlabView === 'todos' ? null : provider === 'linear' && !linearConnected ? null : ( - - 0 || + (appliedGithubProjectSearch !== undefined && + appliedGithubProjectSearch.length > 0) + : provider === 'github' + ? query.trim() !== getTaskPresetQuery(githubPreset).trim() + : undefined + } + editable={taskUiReady} onSubmitEditing={() => { if (!taskUiReady) { return } - if (provider === 'github' && githubMode === 'project') { + if (isGithubProjectSearch) { applyGitHubProjectSearch() return } @@ -9091,42 +9094,38 @@ export default function MobileTasksScreen() { } }} onBlur={() => { - if (provider === 'github' && githubMode === 'project') { + if (isGithubProjectSearch) { applyGitHubProjectSearch() } }} + // Why: Project clear means unfiltered results ('' override when the view + // has a default filter), not restore view default. GitHub items clear + // restores the preset query. Linear clears and persists empty resume. + onClear={() => { + if (isGithubProjectSearch) { + const viewFilter = githubProjectTable?.selectedView.filter ?? '' + setGithubProjectSearch('') + // Why: undefined = use view default; '' = explicit unfiltered override. + setAppliedGithubProjectSearch(viewFilter ? '' : undefined) + return + } + if (provider === 'github') { + const nextQuery = getTaskPresetQuery(githubPreset) + setQuery(nextQuery) + setAppliedQuery(nextQuery) + persistTaskResumeState({ + githubItemsPreset: githubPreset, + githubItemsQuery: nextQuery + }) + return + } + setQuery('') + setAppliedQuery('') + if (provider === 'linear') { + persistTaskResumeState({ linearQuery: '' }) + } + }} /> - {(provider === 'github' && githubMode === 'project' - ? githubProjectSearch.length > 0 || appliedGithubProjectSearch !== undefined - : query.length > 0) && ( - { - if (provider === 'github' && githubMode === 'project') { - const viewFilter = githubProjectTable?.selectedView.filter ?? '' - setGithubProjectSearch('') - setAppliedGithubProjectSearch(viewFilter ? '' : undefined) - return - } - if (provider === 'github') { - const nextQuery = getTaskPresetQuery(githubPreset) - setQuery(nextQuery) - setAppliedQuery(nextQuery) - persistTaskResumeState({ - githubItemsPreset: githubPreset, - githubItemsQuery: nextQuery - }) - return - } - setQuery('') - setAppliedQuery('') - if (provider === 'linear') { - persistTaskResumeState({ linearQuery: '' }) - } - }} - > - - - )} )} @@ -13818,20 +13817,11 @@ const styles = StyleSheet.create({ color: colors.textSecondary }, searchBar: { - flexDirection: 'row', - alignItems: 'center', paddingHorizontal: spacing.md, - paddingVertical: spacing.xs + 2, - gap: spacing.sm, - borderTopWidth: 1, + paddingVertical: spacing.sm, + borderTopWidth: StyleSheet.hairlineWidth, borderTopColor: colors.borderSubtle }, - searchInput: { - flex: 1, - color: colors.textPrimary, - fontSize: 13, - paddingVertical: 2 - }, errorBanner: { paddingHorizontal: spacing.lg, paddingVertical: spacing.sm, diff --git a/mobile/src/components/MobileSearchField.tsx b/mobile/src/components/MobileSearchField.tsx new file mode 100644 index 000000000..2dfd6bf26 --- /dev/null +++ b/mobile/src/components/MobileSearchField.tsx @@ -0,0 +1,201 @@ +import { useEffect, useRef, useState } from 'react' +import { + InteractionManager, + Platform, + Pressable, + StyleSheet, + TextInput, + View, + type TextInputProps +} from 'react-native' +import { Search, X } from 'lucide-react-native' +import { colors, radii, spacing, typography } from '../theme/mobile-theme' + +// Why: toolbar/list chrome paints and settles after the open tap; native +// autoFocus alone often fails to raise the soft keyboard on iOS/Android. +const SEARCH_AUTO_FOCUS_DELAY_MS = 120 + +type MobileSearchFieldProps = { + value: string + onChangeText: (text: string) => void + placeholder: string + onClear?: () => void + /** Override clear-button visibility (default: value is non-empty). */ + showClear?: boolean + clearAccessibilityLabel?: string + autoFocus?: boolean + /** Re-run delayed focus when this identity changes (e.g. each time search opens). */ + focusKey?: unknown + returnKeyType?: TextInputProps['returnKeyType'] + onSubmitEditing?: TextInputProps['onSubmitEditing'] + onBlur?: TextInputProps['onBlur'] + editable?: boolean + accessibilityLabel?: string +} + +/** + * Raised search field used on list screens. Sits above the base/panel canvas + * so it reads as a tappable control instead of chrome that blends into the list. + */ +export function MobileSearchField({ + value, + onChangeText, + placeholder, + onClear, + showClear, + clearAccessibilityLabel = 'Clear search', + autoFocus = false, + focusKey, + returnKeyType = 'search', + onSubmitEditing, + onBlur, + editable = true, + accessibilityLabel +}: MobileSearchFieldProps) { + const inputRef = useRef(null) + const [focused, setFocused] = useState(false) + const clearVisible = showClear ?? value.length > 0 + + useEffect(() => { + if (!autoFocus || !editable) { + return + } + + let timeout: ReturnType | undefined + // Why: wait for the open-press interaction + layout to finish, then focus + // so the soft keyboard actually appears (not just a caret with no IME). + const task = InteractionManager.runAfterInteractions(() => { + timeout = setTimeout(() => { + inputRef.current?.focus() + }, SEARCH_AUTO_FOCUS_DELAY_MS) + }) + + return () => { + task.cancel() + if (timeout) { + clearTimeout(timeout) + } + } + }, [autoFocus, editable, focusKey]) + + function handleClear() { + if (onClear) { + onClear() + } else { + onChangeText('') + } + // Why: pressing the clear chip steals focus and drops the keyboard; + // re-focus so the user can keep typing without tapping the field again. + requestAnimationFrame(() => { + inputRef.current?.focus() + }) + } + + return ( + + + setFocused(true)} + onBlur={(event) => { + setFocused(false) + onBlur?.(event) + }} + clearButtonMode="never" + accessibilityLabel={accessibilityLabel ?? placeholder} + selectionColor={colors.accentBlue} + /> + {clearVisible ? ( + [styles.clearButton, pressed && styles.clearButtonPressed]} + > + {/* Why: chip + larger hit target — a bare 14px X was hard to tap and + read as decoration rather than a clear control. */} + + + + + ) : null} + + ) +} + +const styles = StyleSheet.create({ + shell: { + minHeight: 42, + flexDirection: 'row', + alignItems: 'center', + gap: spacing.sm, + // Why: bgRaised lifts the field off bgBase/bgPanel so search is an obvious + // control, matching TextInputModal / MobilePrBasePicker input shells. + backgroundColor: colors.bgRaised, + borderWidth: 1, + borderColor: colors.borderSubtle, + borderRadius: radii.input, + paddingLeft: spacing.md, + paddingRight: spacing.xs, + paddingVertical: Platform.OS === 'ios' ? spacing.sm : spacing.xs + 2 + }, + shellFocused: { + // Why: monochrome focus cue without burning the blue accent token + // (reserved for state/selection). textMuted reads clearly on bgRaised. + borderColor: colors.textMuted + }, + shellDisabled: { + opacity: 0.55 + }, + input: { + flex: 1, + minWidth: 0, + padding: 0, + margin: 0, + color: colors.textPrimary, + fontSize: typography.bodySize, + // Why: Android TextInput draws extra vertical padding that misaligns the + // icon/clear chip unless we zero it out. + includeFontPadding: false, + textAlignVertical: 'center' + }, + clearButton: { + minWidth: 36, + minHeight: 36, + alignItems: 'center', + justifyContent: 'center' + }, + clearButtonPressed: { + opacity: 0.7 + }, + clearChip: { + width: 24, + height: 24, + borderRadius: 12, + alignItems: 'center', + justifyContent: 'center', + // Why: textMuted reads as a solid chip on bgRaised; borderSubtle was nearly + // invisible and made the clear control feel like decorative chrome. + backgroundColor: colors.textMuted + } +})