键盘激活时忽略屏幕的其余部分

Ignore rest of screen when keyboard active

所以我正在对我的应用程序进行最后的润色,并且存在一段时间的一个错误是当它们的键盘处于活动状态时,我可以使用键盘在屏幕上半部分进行导航仍在显示

有没有一种简单的方法可以在键盘处于活动状态时消除屏幕上半部分的所有其他触摸?如果你能给我指出正确的方向,那就太好了。

寻找类似的东西:When keyboard active then touch screen anywhere, close keyboard

编辑:如果键盘输出到的 textInput 仍然可以触摸就更好了

如果 TextInput 的父视图是 ScrollView,那么你可以使用属性 'keyboardShouldPersistTaps',

<ScrollView keyboardShouldPersistTaps='handled' />

如果您正在使用 View 并且不想滚动,那么您可能可以将其包装在

//This should disable scroll
<ScrollView scrollEnabled={false} >

keyboardShouldPersistTaps 文档(React Native 网站)

keyboardShouldPersistTaps?: enum('always', 'never', 'handled', false, true) #

Determines when the keyboard should stay visible after a tap.

'never' (the default), tapping outside of the focused text input when the keyboard is up dismisses the keyboard. When this happens, children won't receive the tap. 'always', the keyboard will not dismiss automatically, and the scroll view will not catch taps, but children of the scroll view can catch taps. 'handled', the keyboard will not dismiss automatically when the tap was handled by a children, (or captured by an ancestor). false, deprecated, use 'never' instead true, deprecated, use 'always' instead