import {useEffect, useRef} from 'react' import {type TextInput, View} from 'react-native' import {useLingui} from '@lingui/react/macro' import {HITSLOP_10} from '#/lib/constants' import {mergeRefs} from '#/lib/merge-refs' import {listenFocusSearch} from '#/state/events' import {useEnableSquareButtons} from '#/state/preferences/enable-square-buttons' import {atoms as a, useTheme} from '#/alf' import {Button, ButtonIcon} from '#/components/Button' import * as TextField from '#/components/forms/TextField' import {MagnifyingGlass_Stroke2_Corner0_Rounded as MagnifyingGlassIcon} from '#/components/icons/MagnifyingGlass' import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times' import {IS_NATIVE} from '#/env' type Props = Omit & { label?: TextField.InputProps['label'] /** * Called when the user presses the (X) button */ onClearText?: () => void hotkey?: boolean ref?: React.Ref } export function SearchInput({ value, label, onClearText, hotkey, ref, ...rest }: Props) { const t = useTheme() const {t: l} = useLingui() const showClear = value && value.length > 0 const internalRef = useRef(null) useEffect(() => { if (!hotkey) return return listenFocusSearch(() => { internalRef.current?.focus() }) }, [hotkey]) const enableSquareButtons = useEnableSquareButtons() return ( {showClear && ( )} ) }