Javascript React Native TouchableWithoutFeedback不工作
我在键盘上创建了一个组件。不带反馈的可触摸包装其孩子。当有人在组件外单击时,键盘应该关闭。我做错了什么 DismissKeyboard.jsJavascript React Native TouchableWithoutFeedback不工作,javascript,react-native,Javascript,React Native,我在键盘上创建了一个组件。不带反馈的可触摸包装其孩子。当有人在组件外单击时,键盘应该关闭。我做错了什么 DismissKeyboard.js const DismissKeyboard = ({children}) => ( <TouchableWithoutFeedback accessible={false} onPress={() => Keyboard.dismiss()} > {children} </Touchable
const DismissKeyboard = ({children}) => (
<TouchableWithoutFeedback
accessible={false}
onPress={() => Keyboard.dismiss()}
>
{children}
</TouchableWithoutFeedback>
);
包装我的文本输入
<DismissKeyboard>
<View style={styles.noteContainer}>
<TextInput
style={styles.noteTextInputStyling}
multiline
value={note}
placeholder={'Tap to edit'}
placeholderTextColor={globals.COLOR.textColor}
onChangeText={(text) => {
setNote(text);
}}
/>
</View>
</DismissKeyboard>
我错过了什么?如果您有任何帮助,我们将不胜感激……请尝试这样使用:
const DismissKeyboard = ({children}) => (
<TouchableWithoutFeedback
accessible={false}
onPress={() => Keyboard.dismiss()}
>
<View>
{children}
</View>
</TouchableWithoutFeedback>
);
试着像这样使用它:
const DismissKeyboard = ({children}) => (
<TouchableWithoutFeedback
accessible={false}
onPress={() => Keyboard.dismiss()}
>
<View>
{children}
</View>
</TouchableWithoutFeedback>
);
尝试使用键盘组合,避免视觉和无反馈触摸,如下所示。请注意使用Keyboard.Disclose而不是Keyboard.Disclose
import React from 'react';
import {
Keyboard, KeyboardAvoidingView, TouchableWithoutFeedback,
} from 'react-native';
const DismissKeyboard = ({ children }) => (
<TouchableWithoutFeedback style={{ flex: 1 }} onPress={Keyboard.dismiss}>
<KeyboardAvoidingView behavior="padding" style={{ flex: 1 }}>
{children}
</KeyboardAvoidingView>
</TouchableWithoutFeedback>
);
尝试使用键盘组合,避免视觉和无反馈触摸,如下所示。请注意使用Keyboard.Disclose而不是Keyboard.Disclose
import React from 'react';
import {
Keyboard, KeyboardAvoidingView, TouchableWithoutFeedback,
} from 'react-native';
const DismissKeyboard = ({ children }) => (
<TouchableWithoutFeedback style={{ flex: 1 }} onPress={Keyboard.dismiss}>
<KeyboardAvoidingView behavior="padding" style={{ flex: 1 }}>
{children}
</KeyboardAvoidingView>
</TouchableWithoutFeedback>
);
你的答案是赢家!你的答案是赢家!