import React, { useRef } from 'react'; import { StyleSheet, View, TouchableOpacity } from 'react-native'; import Icon from 'react-native-vector-icons/Feather'; import { useLanguage } from 'ordering-components/native'; import { useTheme } from 'styled-components/native'; import { OInput, OButton, OIconButton } from '../shared'; export const SearchBar = (props: any) => { const { searchValue, placeholder, onSearch, onCancel, lazyLoad, isCancelButtonShow, isCancelXButtonShow, noBorderShow, borderStyle, containerStyle } = props; const [, t] = useLanguage(); const theme = useTheme(); const inputRef = useRef(); const handleClear = () => { onSearch(''); }; const handleActiveInput = () => { inputRef?.current?.focus?.(); }; let timeout: null | any = null; const onChangeSearch = (e: any) => { if (!lazyLoad) { onSearch(e); } else { clearTimeout(timeout); timeout = setTimeout(function () { onSearch(e); }, 1000); } }; const styles = StyleSheet.create({ container: { width: 225, flexDirection: 'row', alignItems: 'center', borderRadius: 7.6, backgroundColor: theme.colors.inputDisabled, }, borderStyle: { borderColor: theme.colors.primary, borderWidth: 1, borderRadius: 10, }, inputStyle: { borderRadius: 7.6, backgroundColor: theme.colors.transparent, borderColor: theme.colors.transparent, borderWidth: 0, }, buttonStyle: { maxHeight: 20, }, }); return ( {isCancelButtonShow && ( )} {isCancelXButtonShow && ( )} { handleActiveInput(); }} /> ); };