TouchableWithoutFeedback

TouchableWithoutFeedback

我已经对此进行了研究并找到了这篇文章:

react-native: hide keyboard

但这对我不起作用。当我触摸屏幕上文本输入字段之外的部分时,我期望输入字段将失去焦点,并且键盘将被关闭。但是,什么都没有发生。光标在输入上持续闪烁。

下面是我尝试的代码。请注意,我正在使用redux-form v6:

import dismissKeyboard from 'dismissKeyboard';

<TouchableWithoutFeedback onPress={()=> dismissKeyboard()}>
        <View style={styles.inputWrap}>
          <Field name="editLocation" component={TextField} />
          <Button onPress={handleSubmit(this.onSubmit)}>Sign In</Button>
        </View>
</TouchableWithoutFeedback>

TextField组件包含TextInput。不知道我做错了什么。

我已经在Genymotion模拟器上使用Samsung S6图像和三星Note 4测试了代码。

最佳答案

您需要检查TouchableWithoutFeedback的尺寸以确保onPress被调用。

08-16 16:36