[英]React-native Keyboard.dismiss dismisses the keyboard when using it
我正在嘗試在 TouchableWithoutFeedback 元素內部使用 Keyboard.dismiss() 並且出於某種原因,無論我將此 TouchableWithoutFeedback 元素放在哪里,當點擊 TextInput 之外的區域時鍵盤不會關閉,但是當點擊鍵盤本身? 為什么會發生這種情況,我該如何解決。 ps 它在不同的項目上運行良好
給 Stack Overflow 工作人員的消息:我的許多線程因為“不清楚”而被鎖定,盡管我對每個線程都非常徹底 不要鎖定此線程
代碼:
return (
<TouchableWithoutFeedback onPress={Keyboard.dismiss()}>
<View style={styles.mainView}>
<View style={styles.topSearchView}>
<Image source={require("../../assets/NewSearchIcon.png")} style={styles.searchIcon} />
<TextInput
placeholder="Search for food you like..."
onChangeText={searchedCoursesHandler}
value={searchedCourses}
onFocus={() => { setInputBorderOnFocus(true) }}
style={{
borderColor: inputBorderOnFocus === true ? "#428463" : "grey",
borderWidth: 2,
width: 260,
height: 50,
marginLeft: 10,
fontSize: 18,
padding: 5,
borderRadius: 8,
fontSize: 16
}}
/>
<TouchableOpacity
onPress={() => { setSearchedCourses("") }}
style={styles.deleteInputTouchable}
>
<Image source={require("../../assets/newXicon.png")} style={styles.xButtonIcon} />
</TouchableOpacity>
</View>
<View style={styles.flatListView}>
<FlatList
data={searchedCourses}
renderItem={({ item }) => (
<TouchableOpacity
onPress={() => {
navigation.navigate('item profile', {
item: item,
});
}}
>
<View style={styles.flatListItemView}>
<Image source={{ uri: item.img }} style={styles.flatListImg} />
<Text>{item.name}</Text>
<Text>{item.price}$</Text>
</View>
</TouchableOpacity>
)}
horizontal={true}
/>
</View>
{
searchedCourses.length < 1 &&
<Image source={require("../../assets/NewPastaImage.png")} style={styles.pastaIcon} />
}
</View>
</TouchableWithoutFeedback>
);
enter code here
更改此<TouchableWithoutFeedback onPress={Keyboard.dismiss()}
>
進入這個
<TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.