Ignore rest of screen when keyboard active

我只是一个虾纸丫 提交于 2021-02-08 10:12:15

问题


So i am adding the final touches to my application, and one bug that has been present for a while is when they keyboard is active, i am able to use the navigation on the upper half of the screen with the keyboard still showing

Is there a simple way to dismiss all other touches on the upper half of the screen when the keyboard is active? If you could point me in the right direction that would be great.

Looking for something similar to this: When keyboard active then touch screen anywhere, close keyboard

EDIT: would be nice if the textInput that the keyboard is outputting to was still touchable


回答1:


If the parent view of the TextInput is a ScrollView, then u can use the prop 'keyboardShouldPersistTaps',

<ScrollView keyboardShouldPersistTaps='handled' />

If you're using a View and dont want scrolling, then probably u can wrap it inside a

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

Documentation for keyboardShouldPersistTaps (React Native website)

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



来源:https://stackoverflow.com/questions/46457077/ignore-rest-of-screen-when-keyboard-active

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!