简体   繁体   English

如何在Native Base上打开键盘时避免双击?

[英]How to avoid double tap when keyboard is open on Native Base?

This is question regarding Native Base framework for React Native applications: 这是关于React Native应用程序的Native Base框架的问题:

Imagine a subscribe screen; 想象一下订阅屏幕; 1 text input and a subscribe button; 1个文本输入和一个订阅按钮;

After I type my email address I want to tap on subscribe button but my first tap only closes the keyboard and I need to tap again to press on button. 在我输入我的电子邮件地址后,我想点击订阅按钮,但我的第一个点击只关闭键盘,我需要再次点击按下按钮。 How this can be avoided? 这怎么可以避免? My expected behaviour is that first tap is a press on button. 我的预期行为是第一次点按是按下按钮。 (As far as I see this is something around < Content > component but I am not sure.) (据我所知,这是<Content>组件的一部分,但我不确定。)

(I have checked this issue on native-base kitchen sink app and same issue occurs there as well. Just go to: 'Forms and Input' section and see 'Fixed Label' ) (我已经在本机厨房水槽应用程序上检查了这个问题,同样的问题也出现在那里。只需转到:'表单和输入'部分并看到'固定标签')

将此作为prop传递给内容组件。

< Content keyboardShouldPersistTaps='always'>

If you use < Content keyboardShouldPersistTaps='always'> , the keypad would not disappear after selecting a button or if you tap outside the input field. 如果您使用< Content keyboardShouldPersistTaps='always'> ,键盘在选择按钮后或在输入字段外点击时不会消失。 To ensure that the keyboard disappears if you tap outside the input field, use 如果在输入字段外部点击,确保键盘消失,请使用

< Content keyboardShouldPersistTaps='handled'>

However, with this, the keyboard would not disappear if you select a button (as opposed to a blank part of the screen) even though the button's onPress event will get fired. 但是,使用此功能,即使按钮的onPress事件将被触发,如果您选择一个按钮(而不是屏幕的空白部分),键盘也不会消失。 To make the keyboard disappear after pressing a button, the onPress handler of the button should call 要在按下按钮后使键盘消失,按钮的onPress处理程序应该调用

Keyboard.dismiss()

Don't forget to include the import statement: 不要忘记包含import语句:

import { Keyboard } from 'react-native';

For further details, see https://facebook.github.io/react-native/docs/scrollview.html#keyboardshouldpersisttaps 有关详细信息,请参阅https://facebook.github.io/react-native/docs/scrollview.html#keyboardshouldpersisttaps

keyboardShouldPersistTaps this property is now exist in ScrollView . keyboardShouldPersistTaps此属性现在存在于ScrollView中

<ScrollView keyboardShouldPersistTaps="always">
     {..content or component}
</ScrollView>

For more detail Please visit on official document 有关详细信息,请访问官方文档

https://facebook.github.io/react-native/docs/scrollview#keyboardshouldpersisttaps https://facebook.github.io/react-native/docs/scrollview#keyboardshouldpersisttaps

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM