Use new TextField for search bar
This commit is contained in:
@@ -305,6 +305,7 @@ export function createThemes({
|
|||||||
} as const
|
} as const
|
||||||
|
|
||||||
const light: Theme = {
|
const light: Theme = {
|
||||||
|
scheme: 'light',
|
||||||
name: 'light',
|
name: 'light',
|
||||||
palette: lightPalette,
|
palette: lightPalette,
|
||||||
atoms: {
|
atoms: {
|
||||||
@@ -390,6 +391,7 @@ export function createThemes({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const dark: Theme = {
|
const dark: Theme = {
|
||||||
|
scheme: 'dark',
|
||||||
name: 'dark',
|
name: 'dark',
|
||||||
palette: darkPalette,
|
palette: darkPalette,
|
||||||
atoms: {
|
atoms: {
|
||||||
@@ -479,6 +481,7 @@ export function createThemes({
|
|||||||
|
|
||||||
const dim: Theme = {
|
const dim: Theme = {
|
||||||
...dark,
|
...dark,
|
||||||
|
scheme: 'dark',
|
||||||
name: 'dim',
|
name: 'dim',
|
||||||
palette: dimPalette,
|
palette: dimPalette,
|
||||||
atoms: {
|
atoms: {
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ export type ThemedAtoms = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
export type Theme = {
|
export type Theme = {
|
||||||
|
scheme: 'light' | 'dark' // for library support
|
||||||
name: ThemeName
|
name: ThemeName
|
||||||
palette: Palette
|
palette: Palette
|
||||||
atoms: ThemedAtoms
|
atoms: ThemedAtoms
|
||||||
|
|||||||
@@ -135,6 +135,8 @@ export function createInput(Component: typeof TextInput) {
|
|||||||
placeholder,
|
placeholder,
|
||||||
value,
|
value,
|
||||||
onChangeText,
|
onChangeText,
|
||||||
|
onFocus,
|
||||||
|
onBlur,
|
||||||
isInvalid,
|
isInvalid,
|
||||||
inputRef,
|
inputRef,
|
||||||
style,
|
style,
|
||||||
@@ -173,8 +175,14 @@ export function createInput(Component: typeof TextInput) {
|
|||||||
ref={refs}
|
ref={refs}
|
||||||
value={value}
|
value={value}
|
||||||
onChangeText={onChangeText}
|
onChangeText={onChangeText}
|
||||||
onFocus={ctx.onFocus}
|
onFocus={e => {
|
||||||
onBlur={ctx.onBlur}
|
ctx.onFocus()
|
||||||
|
onFocus?.(e)
|
||||||
|
}}
|
||||||
|
onBlur={e => {
|
||||||
|
ctx.onBlur()
|
||||||
|
onBlur?.(e)
|
||||||
|
}}
|
||||||
placeholder={placeholder || label}
|
placeholder={placeholder || label}
|
||||||
placeholderTextColor={t.palette.contrast_500}
|
placeholderTextColor={t.palette.contrast_500}
|
||||||
keyboardAppearance={t.name === 'light' ? 'light' : 'dark'}
|
keyboardAppearance={t.name === 'light' ? 'light' : 'dark'}
|
||||||
@@ -188,8 +196,8 @@ export function createInput(Component: typeof TextInput) {
|
|||||||
a.px_xs,
|
a.px_xs,
|
||||||
{
|
{
|
||||||
// paddingVertical doesn't work w/multiline - esb
|
// paddingVertical doesn't work w/multiline - esb
|
||||||
paddingTop: 14,
|
paddingTop: 10,
|
||||||
paddingBottom: 14,
|
paddingBottom: 11,
|
||||||
lineHeight: a.text_md.fontSize * 1.1875,
|
lineHeight: a.text_md.fontSize * 1.1875,
|
||||||
textAlignVertical: rest.multiline ? 'top' : undefined,
|
textAlignVertical: rest.multiline ? 'top' : undefined,
|
||||||
minHeight: rest.multiline ? 80 : undefined,
|
minHeight: rest.multiline ? 80 : undefined,
|
||||||
@@ -197,8 +205,8 @@ export function createInput(Component: typeof TextInput) {
|
|||||||
},
|
},
|
||||||
// fix for autofill styles covering border
|
// fix for autofill styles covering border
|
||||||
web({
|
web({
|
||||||
paddingTop: 12,
|
paddingTop: 10,
|
||||||
paddingBottom: 12,
|
paddingBottom: 11,
|
||||||
marginTop: 2,
|
marginTop: 2,
|
||||||
marginBottom: 2,
|
marginBottom: 2,
|
||||||
}),
|
}),
|
||||||
|
|||||||
+109
-104
@@ -35,7 +35,6 @@ import {
|
|||||||
SearchTabNavigatorParams,
|
SearchTabNavigatorParams,
|
||||||
} from '#/lib/routes/types'
|
} from '#/lib/routes/types'
|
||||||
import {augmentSearchQuery} from '#/lib/strings/helpers'
|
import {augmentSearchQuery} from '#/lib/strings/helpers'
|
||||||
import {useTheme} from '#/lib/ThemeContext'
|
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {isNative, isWeb} from '#/platform/detection'
|
import {isNative, isWeb} from '#/platform/detection'
|
||||||
import {listenSoftReset} from '#/state/events'
|
import {listenSoftReset} from '#/state/events'
|
||||||
@@ -57,9 +56,15 @@ import {Text} from '#/view/com/util/text/Text'
|
|||||||
import {CenteredView, ScrollView} from '#/view/com/util/Views'
|
import {CenteredView, ScrollView} from '#/view/com/util/Views'
|
||||||
import {Explore} from '#/view/screens/Search/Explore'
|
import {Explore} from '#/view/screens/Search/Explore'
|
||||||
import {SearchLinkCard, SearchProfileCard} from '#/view/shell/desktop/Search'
|
import {SearchLinkCard, SearchProfileCard} from '#/view/shell/desktop/Search'
|
||||||
import {atoms as a, useTheme as useThemeNew} from '#/alf'
|
import {atoms as a, useBreakpoints,useTheme as useThemeNew, web} from '#/alf'
|
||||||
|
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
||||||
import * as FeedCard from '#/components/FeedCard'
|
import * as FeedCard from '#/components/FeedCard'
|
||||||
|
import * as TextField from '#/components/forms/TextField'
|
||||||
|
import {MagnifyingGlass2_Stroke2_Corner0_Rounded as MagnifyingGlass} from '#/components/icons/MagnifyingGlass2'
|
||||||
import {Menu_Stroke2_Corner0_Rounded as Menu} from '#/components/icons/Menu'
|
import {Menu_Stroke2_Corner0_Rounded as Menu} from '#/components/icons/Menu'
|
||||||
|
import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times'
|
||||||
|
|
||||||
|
const HEADER_HEIGHT = 56
|
||||||
|
|
||||||
function Loader() {
|
function Loader() {
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
@@ -448,14 +453,14 @@ SearchScreenInner = React.memo(SearchScreenInner)
|
|||||||
export function SearchScreen(
|
export function SearchScreen(
|
||||||
props: NativeStackScreenProps<SearchTabNavigatorParams, 'Search'>,
|
props: NativeStackScreenProps<SearchTabNavigatorParams, 'Search'>,
|
||||||
) {
|
) {
|
||||||
|
const t = useThemeNew()
|
||||||
|
const {gtMobile} = useBreakpoints()
|
||||||
const navigation = useNavigation<NavigationProp>()
|
const navigation = useNavigation<NavigationProp>()
|
||||||
const textInput = React.useRef<TextInput>(null)
|
const textInput = React.useRef<TextInput>(null)
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const pal = usePalette('default')
|
|
||||||
const {track} = useAnalytics()
|
const {track} = useAnalytics()
|
||||||
const setDrawerOpen = useSetDrawerOpen()
|
const setDrawerOpen = useSetDrawerOpen()
|
||||||
const setMinimalShellMode = useSetMinimalShellMode()
|
const setMinimalShellMode = useSetMinimalShellMode()
|
||||||
const {isTabletOrDesktop, isTabletOrMobile} = useWebMediaQueries()
|
|
||||||
|
|
||||||
// Query terms
|
// Query terms
|
||||||
const queryParam = props.route?.params?.q ?? ''
|
const queryParam = props.route?.params?.q ?? ''
|
||||||
@@ -507,13 +512,6 @@ export function SearchScreen(
|
|||||||
textInput.current?.focus()
|
textInput.current?.focus()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const onPressCancelSearch = React.useCallback(() => {
|
|
||||||
scrollToTopWeb()
|
|
||||||
textInput.current?.blur()
|
|
||||||
setShowAutocomplete(false)
|
|
||||||
setSearchText(queryParam)
|
|
||||||
}, [queryParam])
|
|
||||||
|
|
||||||
const onChangeText = React.useCallback(async (text: string) => {
|
const onChangeText = React.useCallback(async (text: string) => {
|
||||||
scrollToTopWeb()
|
scrollToTopWeb()
|
||||||
setSearchText(text)
|
setSearchText(text)
|
||||||
@@ -586,6 +584,14 @@ export function SearchScreen(
|
|||||||
[updateSearchHistory, navigation],
|
[updateSearchHistory, navigation],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const onPressCancelSearch = React.useCallback(() => {
|
||||||
|
scrollToTopWeb()
|
||||||
|
textInput.current?.blur()
|
||||||
|
setShowAutocomplete(false)
|
||||||
|
setSearchText('')
|
||||||
|
navigateToItem('')
|
||||||
|
}, [setSearchText, navigateToItem])
|
||||||
|
|
||||||
const onSubmit = React.useCallback(() => {
|
const onSubmit = React.useCallback(() => {
|
||||||
navigateToItem(searchText)
|
navigateToItem(searchText)
|
||||||
}, [navigateToItem, searchText])
|
}, [navigateToItem, searchText])
|
||||||
@@ -667,23 +673,32 @@ export function SearchScreen(
|
|||||||
<View style={isWeb ? null : {flex: 1}}>
|
<View style={isWeb ? null : {flex: 1}}>
|
||||||
<CenteredView
|
<CenteredView
|
||||||
style={[
|
style={[
|
||||||
styles.header,
|
a.p_md,
|
||||||
pal.border,
|
a.pb_0,
|
||||||
pal.view,
|
a.flex_row,
|
||||||
isTabletOrDesktop && {paddingTop: 10},
|
a.gap_sm,
|
||||||
|
t.atoms.bg,
|
||||||
|
web({
|
||||||
|
height: HEADER_HEIGHT, // TODO
|
||||||
|
position: 'sticky',
|
||||||
|
top: 0,
|
||||||
|
zIndex: 1,
|
||||||
|
}),
|
||||||
]}
|
]}
|
||||||
sideBorders={isTabletOrDesktop}>
|
sideBorders={gtMobile}>
|
||||||
{isTabletOrMobile && (
|
{!gtMobile && (
|
||||||
<Pressable
|
<Button
|
||||||
testID="viewHeaderBackOrMenuBtn"
|
testID="viewHeaderBackOrMenuBtn"
|
||||||
onPress={onPressMenu}
|
onPress={onPressMenu}
|
||||||
hitSlop={HITSLOP_10}
|
hitSlop={HITSLOP_10}
|
||||||
style={styles.headerMenuBtn}
|
label={_(msg`Menu`)}
|
||||||
accessibilityRole="button"
|
accessibilityHint={_(msg`Access navigation links and settings`)}
|
||||||
accessibilityLabel={_(msg`Menu`)}
|
size="large"
|
||||||
accessibilityHint={_(msg`Access navigation links and settings`)}>
|
variant="ghost"
|
||||||
<Menu size="lg" fill={pal.colors.textLight} />
|
color="secondary"
|
||||||
</Pressable>
|
shape="square">
|
||||||
|
<ButtonIcon icon={Menu} size="lg" />
|
||||||
|
</Button>
|
||||||
)}
|
)}
|
||||||
<SearchInputBox
|
<SearchInputBox
|
||||||
textInput={textInput}
|
textInput={textInput}
|
||||||
@@ -695,18 +710,21 @@ export function SearchScreen(
|
|||||||
onPressClearQuery={onPressClearQuery}
|
onPressClearQuery={onPressClearQuery}
|
||||||
/>
|
/>
|
||||||
{showAutocomplete && (
|
{showAutocomplete && (
|
||||||
<View style={[styles.headerCancelBtn]}>
|
<Button
|
||||||
<Pressable
|
label={_(msg`Cancel search`)}
|
||||||
onPress={onPressCancelSearch}
|
size="large"
|
||||||
accessibilityRole="button"
|
variant="ghost"
|
||||||
hitSlop={HITSLOP_10}>
|
color="secondary"
|
||||||
<Text style={pal.text}>
|
style={[a.px_sm]}
|
||||||
<Trans>Cancel</Trans>
|
onPress={onPressCancelSearch}
|
||||||
</Text>
|
hitSlop={HITSLOP_10}>
|
||||||
</Pressable>
|
<ButtonText>
|
||||||
</View>
|
<Trans>Cancel</Trans>
|
||||||
|
</ButtonText>
|
||||||
|
</Button>
|
||||||
)}
|
)}
|
||||||
</CenteredView>
|
</CenteredView>
|
||||||
|
|
||||||
<View
|
<View
|
||||||
style={{
|
style={{
|
||||||
display: showAutocomplete ? 'flex' : 'none',
|
display: showAutocomplete ? 'flex' : 'none',
|
||||||
@@ -760,78 +778,67 @@ let SearchInputBox = ({
|
|||||||
onSubmit: () => void
|
onSubmit: () => void
|
||||||
onPressClearQuery: () => void
|
onPressClearQuery: () => void
|
||||||
}): React.ReactNode => {
|
}): React.ReactNode => {
|
||||||
const pal = usePalette('default')
|
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const theme = useTheme()
|
const t = useThemeNew()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Pressable
|
<View style={[a.flex_1, a.relative]}>
|
||||||
// This only exists only for extra hitslop so don't expose it to the a11y tree.
|
<TextField.Root>
|
||||||
accessible={false}
|
<TextField.Icon icon={MagnifyingGlass} />
|
||||||
focusable={false}
|
<TextField.Input
|
||||||
// @ts-ignore web-only
|
inputRef={textInput}
|
||||||
tabIndex={-1}
|
label={_(msg`Search`)}
|
||||||
style={[
|
value={searchText}
|
||||||
{backgroundColor: pal.colors.backgroundLight},
|
placeholder={_(msg`Search`)}
|
||||||
styles.headerSearchContainer,
|
returnKeyType="search"
|
||||||
// @ts-expect-error web only
|
onChangeText={onChangeText}
|
||||||
isWeb && {
|
onSubmitEditing={onSubmit}
|
||||||
cursor: 'default',
|
onFocus={() => {
|
||||||
},
|
if (isWeb) {
|
||||||
]}
|
// Prevent a jump on iPad by ensuring that
|
||||||
onPress={() => {
|
// the initial focused render has no result list.
|
||||||
textInput.current?.focus()
|
requestAnimationFrame(() => {
|
||||||
}}>
|
setShowAutocomplete(true)
|
||||||
<MagnifyingGlassIcon
|
})
|
||||||
style={[pal.icon, styles.headerSearchIcon]}
|
} else {
|
||||||
size={20}
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
testID="searchTextInput"
|
|
||||||
ref={textInput}
|
|
||||||
placeholder={_(msg`Search`)}
|
|
||||||
placeholderTextColor={pal.colors.textLight}
|
|
||||||
returnKeyType="search"
|
|
||||||
value={searchText}
|
|
||||||
style={[pal.text, styles.headerSearchInput]}
|
|
||||||
keyboardAppearance={theme.colorScheme}
|
|
||||||
selectTextOnFocus={isNative}
|
|
||||||
onFocus={() => {
|
|
||||||
if (isWeb) {
|
|
||||||
// Prevent a jump on iPad by ensuring that
|
|
||||||
// the initial focused render has no result list.
|
|
||||||
requestAnimationFrame(() => {
|
|
||||||
setShowAutocomplete(true)
|
setShowAutocomplete(true)
|
||||||
})
|
}
|
||||||
} else {
|
}}
|
||||||
setShowAutocomplete(true)
|
keyboardAppearance={t.scheme}
|
||||||
}
|
selectTextOnFocus={isNative}
|
||||||
}}
|
autoFocus={false}
|
||||||
onChangeText={onChangeText}
|
accessibilityRole="search"
|
||||||
onSubmitEditing={onSubmit}
|
autoCorrect={false}
|
||||||
autoFocus={false}
|
autoComplete="off"
|
||||||
accessibilityRole="search"
|
autoCapitalize="none"
|
||||||
accessibilityLabel={_(msg`Search`)}
|
/>
|
||||||
accessibilityHint=""
|
</TextField.Root>
|
||||||
autoCorrect={false}
|
|
||||||
autoComplete="off"
|
|
||||||
autoCapitalize="none"
|
|
||||||
/>
|
|
||||||
{showAutocomplete && searchText.length > 0 && (
|
{showAutocomplete && searchText.length > 0 && (
|
||||||
<Pressable
|
<View
|
||||||
testID="searchTextInputClearBtn"
|
style={[
|
||||||
onPress={onPressClearQuery}
|
a.absolute,
|
||||||
accessibilityRole="button"
|
a.z_10,
|
||||||
accessibilityLabel={_(msg`Clear search query`)}
|
a.my_auto,
|
||||||
accessibilityHint=""
|
a.inset_0,
|
||||||
hitSlop={HITSLOP_10}>
|
a.justify_center,
|
||||||
<FontAwesomeIcon
|
a.pr_sm,
|
||||||
icon="xmark"
|
{left: 'auto'},
|
||||||
size={16}
|
]}>
|
||||||
style={pal.textLight as FontAwesomeIconStyle}
|
<Button
|
||||||
/>
|
testID="searchTextInputClearBtn"
|
||||||
</Pressable>
|
onPress={onPressClearQuery}
|
||||||
|
label={_(msg`Clear search query`)}
|
||||||
|
hitSlop={HITSLOP_10}
|
||||||
|
size="tiny"
|
||||||
|
shape="round"
|
||||||
|
variant="ghost"
|
||||||
|
color="secondary">
|
||||||
|
<ButtonIcon icon={X} size="sm" />
|
||||||
|
</Button>
|
||||||
|
</View>
|
||||||
)}
|
)}
|
||||||
</Pressable>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
SearchInputBox = React.memo(SearchInputBox)
|
SearchInputBox = React.memo(SearchInputBox)
|
||||||
@@ -1029,8 +1036,6 @@ function scrollToTopWeb() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const HEADER_HEIGHT = 46
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
header: {
|
header: {
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
@@ -1038,7 +1043,7 @@ const styles = StyleSheet.create({
|
|||||||
paddingHorizontal: 12,
|
paddingHorizontal: 12,
|
||||||
paddingLeft: 13,
|
paddingLeft: 13,
|
||||||
paddingVertical: 4,
|
paddingVertical: 4,
|
||||||
height: HEADER_HEIGHT,
|
height: isWeb ? HEADER_HEIGHT : undefined,
|
||||||
// @ts-ignore web only
|
// @ts-ignore web only
|
||||||
position: isWeb ? 'sticky' : '',
|
position: isWeb ? 'sticky' : '',
|
||||||
top: 0,
|
top: 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user