Bug情况描述:React Native项目中,点击按钮A出现弹框浮层,弹框中需要TextInput输入数字,键盘浮起来;这时候点击 取消按钮L 或者 确定按钮R,只是让键盘收起,但是并没有触发 取消 或 确定 的事件,必须要再点击第二次才可以触发。另外,当输入框有焦点的情况下,点击 屏幕任意位置(除了键盘),可使键盘收起隐藏;
期待效果:当输入框输完数字后,光标焦点仍然存在,键盘也未消失,这时候点击一次取消按钮
L
即可让弹框层和键盘同时隐藏;点击一次确定按钮R即可跳转到另一个页面;
style={styles.input1}
placeholder="请输入短信验证码"
placeholderTextColor={Color.CM_InputTextColor}
maxLength={6}
keyboardType={'numeric'}
onChangeText={(code) => {
if (this.state.jdAuth) {
Config.JDMobileCode = code;
}else {
Config.ChinaMobileCode = code;
this.setState({
password: code
value={this.state.password}
onEndEditing={()=>{this.endEdit()}}
由于我这里是有取消和确定两个按钮需要触发事件的,我在初始化的时候定义了一个标志位变量,用来表示点击的是左按钮还是右按钮,然后在其相应的事件中赋值不同标志位。在执行了endEdit()函数中判断标志位的值,进而执行取消事件还是确定事件,即可。
endEdit(){
if(this.state.isLeft==1){
this.hideModal();
}else if(this.state.isLeft==2){
this.btnOK();
注:目前仍存在一点问题,有更好的解决办法,日后会持续更新。。。也欢迎大佬们留言板分享最佳解决方案
==============================更新======================================
上次说的还有点问题,是第二次进入的时候,第一次点击确定或者取消按钮可以触发。现在bug解决了,添加以下代码:
1.在TextInput组件中加入onSubmitEditing属性,且执行让键盘主动消失的函数;
<TextInput
ref="inputWR"
style={styles.input1}
placeholder="请输入短信验证码"
placeholderTextColor={Color.CM_InputTextColor}
maxLength={6}
keyboardType={'numeric'}
onChangeText={(code) => {
if (this.state.jdAuth) {
Config.JDMobileCode = code;
else {
Config.ChinaMobileCode = code;
this.setState({
password: code
value={this.state.password}
onEndEditing={()=> {
this.testWR()
onSubmitEditing={()=>{this.testBlur()}}
2.写testBlur函数:
testBlur(){
this.refs.inputWR.blur();
现在测试完美了~~~~~~
由于Alert https://blog.csdn.net/zhaihaohao1/article/details/88632787
不能自己定义样式,所以使用Modal可以自己定义样式
代码(复制即可运行):
ModalExample.js
import React, {Com...
关于react native TextInput 键盘弹起点击两次才能触发子组件解决方案:
1. TextInput组件用ScrollView或FlatList组件包裹,给ScrollView或FlatList组件添加如下属性:
keyboardShouldPersistTaps="handled"
'handled',当点击事件被子组件捕获时,键盘不会自动收起。这样切换TextInpu...
解决方法:
用ScrollView作为Textinput的外层,在ScrollView上使用keyboardShouldPersistTaps={'always'},了解一下。
TextInput控件后面根了一个搜索按钮,当TextInput中输入内容后,点击搜索获取内容,并触发搜索, Bug : 不能触发回调
解决: keyboardShouldPersistTaps={'always'}
keyboardShouldPersistTaps enum('always', 'ne...
keyboardShouldPersistTaps={'handled'}
<ScrollView keyboardShouldPersistTaps={'handled'} contentContainerStyle={{height: '100%'}}>
<TextInput ..../>
</View>
</ScrollView>
就可以解决问题。
如果使用 属性为alw
当输入框获取获取焦点后, 再点击其他的子控件中的可点击控件, 不能触发点击事件
解决方法, 在 ``, <FlatList> 等内部是虚拟列表的标签上添加属性 keyboardShouldPersistTaps="handled" 可以解决.
官网 https://reactnative.dev/docs/scrollview#keyboardshouldpersisttaps 有说明:
keyboardShouldPersistTaps
Determines when the keyboard
element单选框的change事件需要点击两次才触发
用element建了一个单选框组,绑定了一个change事件,测试内容为,绑定值改变后在测试台输出“我被点击啦”,但是在测试时,第一次点击都是无效的,只有第二次开始控制台才会输出
先放源代码
<form action="welcome.php" method="POST" target="fmResult">
<div id="app">
<span>第{{round}}轮投
import React, {Component} from "react";
import {
StyleSheet, Text, View, TextInput, Dimensions,Platform
} from "react-nati...
报错Cannot use [chunkhash] or [contenthash] for chunk in '[name][chunkhash:8].js' (use [hash] instead)
我本不黑:
WebStorm之如何清除缓存
sanjilaoye:
报错The code generator has deoptimised the styling of ...as it exceeds the max of 500KB.
超级码吏:
报错The code generator has deoptimised the styling of ...as it exceeds the max of 500KB.
爱吃土豆的兔子:
报错The code generator has deoptimised the styling of ...as it exceeds the max of 500KB.
singularityDZF: