React Native TextInput 模糊消耗 TouchableHighlight 按下事件

React Native TextInput blur consumes TouchableHighlight press event

我有一个 <TextInput>,我想在点击红色 Post 按钮时提交 <TouchableHighlight>。当 TextInput 获得焦点时,我完成输入并点击 Post 按钮,键盘关闭但按钮未注册点击。

我尝试使用 TextInput onBlur 事件,但它没有给我触摸点的坐标,所以我不知道触摸点是否真的在按钮上。

您需要将 属性 keyboardShouldPersistTaps={true} 添加到您的 ScrollView。

docs 是这样说的:

keyboardShouldPersistTaps bool:

When false, tapping outside of the focused text input when the keyboard is up dismisses the keyboard. When true, the scroll view will not catch taps, and the keyboard will not dismiss automatically. The default value is false.

@frank,我想你找到了一个可行的解决方案,但除了 'keyboardShouldPersistTaps',如果你将你的视图包装在一个 TouchableWithoutFeedback 元素中,并带有一个调用 dismissKeyboard 的 onPress,它应该可以解决这个问题。

 <ScrollView keyboardShouldPersistTaps={true} ref='scrollView'>
   <TouchableWithoutFeedback onPress={dismissKeyboard}>
     <View>
     -View Content-
     </View>
  </TouchableWithoutFeedback>
</ScrollView>