I want to make suggestion for my text input. When I focus on a TextInput, a list of title suggestions should appear. While I am typing, I should be able to click on the desired title. The suggestion feature works well. The problem starts when the TouchableOpacity can't be clicked while the keyboard is open. However, the TouchableOpacity can be clicked when I hide the keyboard first by clicking the back button (If I tap on the screen, it triggers the onBlur method, causing the list to disappear). The expected behavior is that TouchableOpacity can be clicked while the keyboard is open.
I've been looking for solutions for similar problem but nothing works on my case. The solutions I've tried are KeyboardAwareScrollView and keyboardShouldPersistTaps
return (
<SafeAreaView style={styles.container}>
<View style={[{ flex: 1 }]}>
<Text>Enter Title</Text>
<TextInput
style={{ width: '100%', height: 60, backgroundColor: 'green' }}
autoCorrect={false}
onChangeText={(val) => {
handleTitleChange()
filterTitle(val);
}}
multiline={false}
onFocus={() => {
setIsTitleFocused(true);
}}
onBlur={() => {
setIsTitleFocused(false);
}}
value={Input.title}
/>
{isTitleFocused && (
<ScrollView contentContainerStyle={{height:200}}>
<FlatList
data={filteredTitle}
renderItem={({ item, index }) => (
<TouchableOpacity
style={{
padding: 10,
backgroundColor: 'gray',
marginVertical: 10,
}}
onPress={() => onTitleSelected(item?.title)}>
<Text style={{color:"white"
}}>{item?.title || ''}</Text>
</TouchableOpacity>
)}
keyExtractor={(item) => item?.title}
/>
</ScrollView>
)}
<Text>Enter Detail</Text>
<TextInput
style={{ width: '100%', height: 60, backgroundColor: 'lightgray' }}
autoCorrect={false}
onChangeText={(val) => {
handleDetailChange()
}}
multiline={false}
value={Input.detail}
/>
</View>
</SafeAreaView>
);
}```
First things first, you don't need the
ScrollViewwrapping theFlatList, you can achieve the same behaviour with only theFlatList. Then, you can set thekeyboardShouldPersistTapsprop on theFlatListto'handled', which according to the documentation will achieve what you needHowever, this might still trigger the
onBlurcallback of theTextInput, I'm not sure there's much room for improvement there.