Fix keyboard dismiss on emoji press

This commit is contained in:
Danish Ahmed Mirza 2022-06-28 03:00:21 +05:30 committed by Danish
parent 8ea5755345
commit 99db6d824d
3 changed files with 38 additions and 25 deletions

View File

@ -10,6 +10,7 @@ import { IEmoji } from '../../definitions';
import shortnameToUnicode from '../../lib/methods/helpers/shortnameToUnicode'; import shortnameToUnicode from '../../lib/methods/helpers/shortnameToUnicode';
import CustomEmoji from '../EmojiPicker/CustomEmoji'; import CustomEmoji from '../EmojiPicker/CustomEmoji';
import database from '../../lib/database'; import database from '../../lib/database';
import styles from './styles';
interface IEmojiSearchbarProps { interface IEmojiSearchbarProps {
openEmoji: () => void; openEmoji: () => void;
@ -21,14 +22,13 @@ interface IEmojiSearchbarProps {
const renderEmoji = (emoji: IEmoji, size: number, baseUrl: string) => { const renderEmoji = (emoji: IEmoji, size: number, baseUrl: string) => {
if (emoji.name) { if (emoji.name) {
return <CustomEmoji style={{ height: size, width: size }} emoji={emoji} baseUrl={baseUrl} />; return <CustomEmoji style={{ height: size, width: size, margin: 4 }} emoji={emoji} baseUrl={baseUrl} />;
} }
return <Text style={{ fontSize: size }}>{shortnameToUnicode(`:${emoji}:`)}</Text>; return <Text style={[styles.searchedEmoji, { fontSize: size }]}>{shortnameToUnicode(`:${emoji}:`)}</Text>;
}; };
const EmojiSearchbar = React.forwardRef<TextInput, IEmojiSearchbarProps>( const EmojiSearchbar = React.forwardRef<TextInput, IEmojiSearchbarProps>(
({ openEmoji, onChangeText, emojis, onEmojiSelected, baseUrl }, ref) => { ({ openEmoji, onChangeText, emojis, onEmojiSelected, baseUrl }, ref) => {
console.log('Emojis', emojis);
const { colors, theme } = useTheme(); const { colors, theme } = useTheme();
const [searchText, setSearchText] = useState<string>(''); const [searchText, setSearchText] = useState<string>('');
const [frequentlyUsed, setFrequentlyUsed] = useState([]); const [frequentlyUsed, setFrequentlyUsed] = useState([]);
@ -60,7 +60,7 @@ const EmojiSearchbar = React.forwardRef<TextInput, IEmojiSearchbarProps>(
const renderItem = (emoji: IEmoji) => { const renderItem = (emoji: IEmoji) => {
const emojiSize = 30; const emojiSize = 30;
return ( return (
<View style={{ justifyContent: 'center', marginHorizontal: 2 }}> <View style={[styles.emojiContainer]}>
<TouchableOpacity <TouchableOpacity
activeOpacity={0.7} activeOpacity={0.7}
// @ts-ignore // @ts-ignore
@ -72,22 +72,18 @@ const EmojiSearchbar = React.forwardRef<TextInput, IEmojiSearchbarProps>(
); );
}; };
return ( return (
<View> <View style={{ borderTopWidth: 1, borderTopColor: colors.borderColor }}>
<View style={{ height: 50, paddingHorizontal: 5 }}> <FlatList
<FlatList horizontal data={searchText ? emojis : frequentlyUsed} renderItem={({ item }) => renderItem(item)} /> horizontal
</View> data={searchText ? emojis : frequentlyUsed}
<View renderItem={({ item }) => renderItem(item)}
style={{ showsHorizontalScrollIndicator={false}
flexDirection: 'row', keyExtractor={item => item.name || item.content}
height: 50, contentContainerStyle={styles.emojiListContainer}
marginVertical: 10, keyboardShouldPersistTaps='always'
justifyContent: 'center', />
alignItems: 'center' <View style={styles.emojiSearchbarContainer}>
}}> <TouchableOpacity style={styles.openEmojiKeyboard} activeOpacity={0.7} onPress={openEmoji}>
<TouchableOpacity
style={{ marginHorizontal: 10, justifyContent: 'center', height: '100%' }}
activeOpacity={0.7}
onPress={openEmoji}>
<CustomIcon name='chevron-left' size={30} color={colors.collapsibleChevron} /> <CustomIcon name='chevron-left' size={30} color={colors.collapsibleChevron} />
</TouchableOpacity> </TouchableOpacity>
<View style={{ flex: 1 }}> <View style={{ flex: 1 }}>
@ -100,8 +96,8 @@ const EmojiSearchbar = React.forwardRef<TextInput, IEmojiSearchbarProps>(
returnKeyType='search' returnKeyType='search'
underlineColorAndroid='transparent' underlineColorAndroid='transparent'
onChangeText={handleTextChange} onChangeText={handleTextChange}
style={{ backgroundColor: colors.passcodeButtonActive, padding: 10, borderRadius: 5 }} style={[styles.emojiSearchbar, { backgroundColor: colors.passcodeButtonActive }]}
containerStyle={{ height: '100%', justifyContent: 'center', marginBottom: 0, marginRight: 15 }} containerStyle={styles.textInputContainer}
value={searchText} value={searchText}
theme={theme} theme={theme}
onClearInput={() => handleTextChange('')} onClearInput={() => handleTextChange('')}

View File

@ -624,9 +624,10 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
this.setShowSend(true); this.setShowSend(true);
break; break;
case EventTypes.SEARCH_PRESSED: case EventTypes.SEARCH_PRESSED:
this.setState({ showEmojiKeyboard: false, showEmojiSearchbar: true }, () => { this.setState({ showEmojiKeyboard: false, showEmojiSearchbar: true });
setTimeout(() => {
this.emojiSearchbarRef.current.focus(); this.emojiSearchbarRef.current.focus();
}); }, 400);
break; break;
default: default:
// Do nothing // Do nothing

View File

@ -157,5 +157,21 @@ export default StyleSheet.create({
fontSize: 12, fontSize: 12,
marginLeft: 4, marginLeft: 4,
...sharedStyles.textRegular ...sharedStyles.textRegular
} },
searchedEmoji: {
backgroundColor: 'transparent',
color: '#ffffff'
},
emojiContainer: { justifyContent: 'center', marginHorizontal: 2 },
emojiListContainer: { height: 50, paddingHorizontal: 5, marginVertical: 5 },
emojiSearchbarContainer: {
flexDirection: 'row',
height: 50,
marginBottom: 10,
justifyContent: 'center',
alignItems: 'center'
},
openEmojiKeyboard: { marginHorizontal: 10, justifyContent: 'center' },
emojiSearchbar: { padding: 10, borderRadius: 5 },
textInputContainer: { justifyContent: 'center', marginBottom: 0, marginRight: 15 }
}); });