使用React native以编程方式显示键盘 [英] Show keyboard programmatically using React native

查看:282
本文介绍了使用React native以编程方式显示键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用React Native以编程方式显示TextInput键盘?使用ScrollView,在TextInput之间点击可以关闭键盘.我想再次使用TextInput的onFocus方法显示Keyboard.无论如何要做到这一点?

How do I show Keyboard for TextInput programmatically using react native? Using a ScrollView, tapping between TextInput causes the keyboard to be dismissed. I want to show the Keyboard again using onFocus method of TextInput. Anyway to accomplish this?

推荐答案

考虑对您的textInput进行引用:

consider have a reference of your textInput :

<TextInput ref={(ref)=>{this.myTextInput = ref}} />

当您需要再次聚焦时,请使用:this.myTextInput.focus()

And when you have to focus it again use : this.myTextInput.focus()

编辑React16

对于react16,请使用React.createRef创建参考.

For react16 use React.createRef to create a reference.

这篇关于使用React native以编程方式显示键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆