[英]react native keyboard dismiss not working
誰能解釋我為什么鍵盤關閉不起作用? 沒有錯誤,也沒有任何反應。
在我的上一個項目中,它有效,但不存在。 我錯了什么?
代碼:
import React, { useState, useEffect } from 'react';
import { StyleSheet, View, Text, TextInput, TouchableOpacity, KeyboardAvoidingView, ScrollView, Dimensions, Keyboard } from 'react-native';
import { AntDesign } from '@expo/vector-icons';
import { LinearGradient } from 'expo-linear-gradient';
const width = Dimensions.get('window').width;
const height = Dimensions.get('window').height;
const Home = () => {
const [searchInput, setSearchInput] = useState('');
return (
<KeyboardAvoidingView onPress={() => Keyboard.dismiss()} style={styles.container}>
<LinearGradient
style={styles.header}
colors={['blue', 'red', 'orange']}
>
<View style={{alignItems: 'flex-end'}}>
<TouchableOpacity>
<AntDesign style={{textAlign: 'right'}} name="pluscircleo" size={42} color="#fff" />
</TouchableOpacity>
</View>
<View style={styles.headerBottom}>
<Text style={styles.headerText}>Treffpunkt</Text>
<TextInput
placeholder="Gebe deinen Code ein"
value={searchInput}
onChangeText={value => setSearchInput(value)}
style={styles.searchInput}
/>
</View>
</LinearGradient>
</KeyboardAvoidingView>
)
};
正如康斯坦丁在評論中提到的, KeyboardAvoidingView
沒有onPress
事件。
您可以在漸變之前有一個子元素,它將為您處理新聞。
您可以在此處參考 expo 示例
<KeyboardAvoidingView
style={styles.container}>
<TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}>
<LinearGradient
style={styles.header}
colors={['blue', 'red', 'orange']}>
<View style={{ alignItems: 'flex-end' }}>
...
</View>
</LinearGradient>
</TouchableWithoutFeedback>
</KeyboardAvoidingView>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.