import React, { useEffect, useRef } from 'react'; import { Platform, TextInput } from 'react-native'; import { Box, Icon, PressBox, Text, createStyleSheet, useHeaderStyle, useUIKitTheme, } from '@gathertown/uikit-react-native-foundation'; import { useLocalization } from '../../../hooks/useContext'; import type { MessageSearchProps } from '../types'; const MessageSearchHeader = ({ keyword, onChangeKeyword, onPressHeaderLeft, onPressHeaderRight, }: MessageSearchProps['Header']) => { const { HeaderComponent } = useHeaderStyle(); const { colors } = useUIKitTheme(); const { STRINGS } = useLocalization(); const inputRef = useRef(null); const inputColor = colors.ui.input.default.active; const searchEnabled = keyword.length > 0; useEffect(() => { setTimeout(() => { inputRef.current?.focus(); }, Platform.select({ ios: 500, default: 0 })); }, []); return ( onPressHeaderRight()} selectionColor={colors.primary} placeholder={STRINGS.MESSAGE_SEARCH.HEADER_INPUT_PLACEHOLDER} placeholderTextColor={inputColor.placeholder} style={[styles.input, { color: inputColor.text }]} value={keyword} onChangeText={onChangeKeyword} /> {searchEnabled && ( onChangeKeyword('')}> )} } left={} onPressLeft={onPressHeaderLeft} right={ {STRINGS.MESSAGE_SEARCH.HEADER_RIGHT} } onPressRight={searchEnabled ? onPressHeaderRight : undefined} /> ); }; const styles = createStyleSheet({ searchIcon: { marginRight: 8, }, clearIcon: { marginLeft: 8, }, input: { flex: 1, height: '100%', fontSize: 14, padding: 0, }, }); export default MessageSearchHeader;