import React, {useRef, useState} from 'react' import {TextInput, View} from 'react-native' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' import {HITSLOP_10} from '#/lib/constants' import {mergeRefs} from '#/lib/merge-refs' import {isNative} from '#/platform/detection' import {atoms as a, useTheme} from '#/alf' import {Button, ButtonIcon} from '#/components/Button' import * as TextField from '#/components/forms/TextField' import {MagnifyingGlass2_Stroke2_Corner0_Rounded as MagnifyingGlassIcon} from '#/components/icons/MagnifyingGlass2' import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times' type SearchInputProps = Omit & { label?: TextField.InputProps['label'] onClearText?: () => void } export const SearchInput = React.forwardRef( function SearchInput( {label, onChangeText: onChangeTextProp, onClearText, ...rest}, ref, ) { const t = useTheme() const {_} = useLingui() const [showClear, setShowClear] = useState(false) const inputRef = useRef() const handleChangeText = (text: string) => { setShowClear(text.length > 0) onChangeTextProp?.(text) } const handleClear = () => { inputRef.current?.clear() setShowClear(false) onChangeTextProp?.('') onClearText?.() } return ( {showClear && ( )} ) }, )