Improve search box on mobile (#8187)
* Redesign mobile search field as a shared, raised component - Extract MobileSearchField from duplicated Search icon + TextInput + clear button markup in worktree list and tasks screens into a reusable component - Give the field a raised bgRaised shell with focus/disabled states so it reads as a tappable control instead of blending into panel chrome - Fix delayed autoFocus via InteractionManager + timeout so the keyboard reliably appears after the search bar opens - Preserve per-screen clear behavior (preset/query fallback for GitHub, project-view filter) via configurable showClear/onClear props * Simplify GitHub project search state checks and fix stuck clear button - Extract `isGithubProjectSearch` to dedupe repeated `provider === 'github' && githubMode === 'project'` checks - Fix showClear so an explicit empty applied override doesn't leave the clear button visible forever
This commit is contained in:
@@ -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 && (
|
||||
<View style={styles.searchBar}>
|
||||
<Search size={14} color={colors.textMuted} />
|
||||
<TextInput
|
||||
style={styles.searchInput}
|
||||
<MobileSearchField
|
||||
value={search}
|
||||
onChangeText={setSearch}
|
||||
placeholder="Search worktrees…"
|
||||
placeholderTextColor={colors.textMuted}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
autoFocus
|
||||
// Why: new key each open remounts focus effect if the field stays mounted
|
||||
// across rapid toggles; pairs with delayed focus so the keyboard appears.
|
||||
focusKey={showSearch}
|
||||
accessibilityLabel="Search worktrees"
|
||||
/>
|
||||
{search.length > 0 && (
|
||||
<Pressable onPress={() => setSearch('')}>
|
||||
<X size={14} color={colors.textSecondary} />
|
||||
</Pressable>
|
||||
)}
|
||||
</View>
|
||||
)}
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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 (
|
||||
<SafeAreaView style={styles.container} edges={['top']}>
|
||||
@@ -9048,31 +9049,33 @@ export default function MobileTasksScreen() {
|
||||
{provider === 'gitlab' && gitlabView === 'todos' ? null : provider === 'linear' &&
|
||||
!linearConnected ? null : (
|
||||
<View style={styles.searchBar}>
|
||||
<Search size={14} color={colors.textMuted} />
|
||||
<TextInput
|
||||
style={styles.searchInput}
|
||||
value={
|
||||
provider === 'github' && githubMode === 'project' ? githubProjectSearch : query
|
||||
}
|
||||
onChangeText={
|
||||
provider === 'github' && githubMode === 'project'
|
||||
? setGithubProjectSearch
|
||||
: setQuery
|
||||
}
|
||||
<MobileSearchField
|
||||
value={isGithubProjectSearch ? githubProjectSearch : query}
|
||||
onChangeText={isGithubProjectSearch ? setGithubProjectSearch : setQuery}
|
||||
placeholder={
|
||||
provider === 'github' && githubMode === 'project'
|
||||
isGithubProjectSearch
|
||||
? 'Search project view...'
|
||||
: `Search ${providerLabel} tasks...`
|
||||
}
|
||||
placeholderTextColor={colors.textMuted}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
returnKeyType="search"
|
||||
// Why: GitHub items seed the field with a preset query, so a bare
|
||||
// value.length check would always show clear. Project mode shows clear
|
||||
// for draft text or a non-empty applied override — not for applied ''
|
||||
// (explicit unfiltered after clear), or the button sticks forever.
|
||||
showClear={
|
||||
isGithubProjectSearch
|
||||
? githubProjectSearch.length > 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) && (
|
||||
<Pressable
|
||||
onPress={() => {
|
||||
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: '' })
|
||||
}
|
||||
}}
|
||||
>
|
||||
<X size={14} color={colors.textSecondary} />
|
||||
</Pressable>
|
||||
)}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
@@ -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,
|
||||
|
||||
@@ -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<TextInput>(null)
|
||||
const [focused, setFocused] = useState(false)
|
||||
const clearVisible = showClear ?? value.length > 0
|
||||
|
||||
useEffect(() => {
|
||||
if (!autoFocus || !editable) {
|
||||
return
|
||||
}
|
||||
|
||||
let timeout: ReturnType<typeof setTimeout> | 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 (
|
||||
<View style={[styles.shell, focused && styles.shellFocused, !editable && styles.shellDisabled]}>
|
||||
<Search
|
||||
size={15}
|
||||
color={focused ? colors.textPrimary : colors.textSecondary}
|
||||
strokeWidth={2.2}
|
||||
/>
|
||||
<TextInput
|
||||
ref={inputRef}
|
||||
style={styles.input}
|
||||
value={value}
|
||||
onChangeText={onChangeText}
|
||||
placeholder={placeholder}
|
||||
// Why: textSecondary keeps the hint readable on bgRaised; textMuted
|
||||
// disappears against the raised shell and makes the field look empty.
|
||||
placeholderTextColor={colors.textSecondary}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
// Still request native auto-focus; the delayed ref focus is the reliable path.
|
||||
autoFocus={autoFocus}
|
||||
showSoftInputOnFocus
|
||||
editable={editable}
|
||||
returnKeyType={returnKeyType}
|
||||
onSubmitEditing={onSubmitEditing}
|
||||
onFocus={() => setFocused(true)}
|
||||
onBlur={(event) => {
|
||||
setFocused(false)
|
||||
onBlur?.(event)
|
||||
}}
|
||||
clearButtonMode="never"
|
||||
accessibilityLabel={accessibilityLabel ?? placeholder}
|
||||
selectionColor={colors.accentBlue}
|
||||
/>
|
||||
{clearVisible ? (
|
||||
<Pressable
|
||||
onPress={handleClear}
|
||||
hitSlop={8}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={clearAccessibilityLabel}
|
||||
style={({ pressed }) => [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. */}
|
||||
<View style={styles.clearChip}>
|
||||
<X size={12} color={colors.surfaceBright} strokeWidth={2.6} />
|
||||
</View>
|
||||
</Pressable>
|
||||
) : null}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user