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

View File

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

View File

@ -157,5 +157,21 @@ export default StyleSheet.create({
fontSize: 12,
marginLeft: 4,
...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 }
});