import Ionicons from '@expo/vector-icons/build/Ionicons'; import React from 'react'; import { StyleSheet, TextInput, TextStyle, TouchableOpacity, View, Platform } from 'react-native'; import { Colors } from '../constants'; export default function SearchBar({ selectionColor, tintColor = Colors.tintColor, placeholderTextColor = '#ccc', underlineColorAndroid = '#ccc', textColor, onSubmit, onChangeQuery, initialValue = '', }: { initialValue?: string; selectionColor?: string; tintColor: string; placeholderTextColor?: string; underlineColorAndroid?: string; textColor?: string; onSubmit?: (query: string) => void; onChangeQuery?: (query: string) => void; }) { const [text, setText] = React.useState(initialValue); const _textInput = React.useRef(null); React.useEffect(() => { requestAnimationFrame(() => { _textInput.current?.focus(); }); }, []); const _handleClear = () => { _handleChangeText(''); }; const _handleChangeText = (text: string) => { setText(text); onChangeQuery?.(text); }; const _handleSubmit = () => { onSubmit?.(text); _textInput.current?.blur(); }; const searchInputStyle: TextStyle = {}; if (textColor) { searchInputStyle.color = textColor; } return ( {text ? ( ) : null} ); } const styles = StyleSheet.create({ container: { flex: 1, flexDirection: 'row', }, searchInput: { flex: 1, fontSize: 18, marginBottom: 2, paddingLeft: Platform.select({ web: 16, default: 5 }), marginRight: 5, ...Platform.select({ web: { outlineColor: 'transparent', }, default: {}, }), }, });