键盘可见时无法单击按钮 - 反应原生

Amr*_*tha 17 react-native react-native-android

我有一个 textInput 和一个按钮。当 textInput 被聚焦时,键盘会出现,但如果你在键盘可见的情况下点击按钮,首先键盘消失,然后只有你可以点击按钮。为什么?我怎样才能让它工作,以便可以在键盘可见的情况下点击按钮?在 android studio(android native)中开发的应用程序可以获取键盘可见的点击监听器。但是在本机反应中,它不起作用。如果你点击按钮以外的任何地方,那么键盘应该消失,不是吗?但是如果你点击键盘可见的按钮,btn 应该接收监听器。我正在android设备上测试它。

PS你可以在这里试试:https : //snack.expo.io/@codebyte99/addcomponents

<TextInput
    placeholder={'Type smth'}
    style={[{ borderBottomColor: 'gray', borderBottomWidth: 1 }]}
/>

<TouchableOpacity onPress={() => { this._onPressOut(); }}>
  <Text>click here</Text>
</TouchableOpacity>
Run Code Online (Sandbox Code Playgroud)

Tha*_*hik 43

滚动视图包含一个keyboardShouldPersistTaps处理滚动视图内键盘点击行为的道具。

对于您的情况,请将其作为 <ScrollView keyboardShouldPersistTaps='handled'>

这是一个带键盘的世博链接滚动视图

  • [GitHub 上的此评论](https://github.com/facebook/react-native/issues/10138#issuecomment-304656278) 指出应在所有父级 `ScrollView` 上设置 `keyboardShouldPersistTaps='handled'`:对我来说,解决方法是我必须在模态的所有滚动视图祖先上设置keyboardShouldPersistTaps...否则,如果父树中的任何ScrollView执行默认keyboardShouldPersistTaps =“none”,键盘将被解雇(在我的情况下,我想要以防止解雇)。 (3认同)

Jus*_*oel 8

仅供参考:如果您使用的是react-native-keyboard-aware-scroll-view,您需要这样做:

<KeyboardAwareScrollView keyboardShouldPersistTaps="always">
Run Code Online (Sandbox Code Playgroud)


ako*_*977 6

作为@thakur-karthik 回答的补充:

需要注意的是,在 scrollview 场景中,当您在 react-native modal 中有一个 scrollview 时,会发生一些奇怪的事情。

只需添加keyboardShouldPersistTaps={'always'}上的模式滚动视图独自将无法正常工作。

如果您在任何祖先中有滚动视图,它们必须keyboardShouldPersistTaps={'always'}在其组件上声明