React Native TouchableHighlight 忽略第一次点击事件 [英] React Native TouchableHighlight ignores the first click event

查看:35
本文介绍了React Native TouchableHighlight 忽略第一次点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 TouchableHighlight 制作按钮,但按钮上的第一个点击事件似乎不会触发 TouchableHighlight 元素上的 onPress 事件.再次单击时它会起作用.

I am using TouchableHighlight for making buttons, but it seems the first click event on the button does not trigger the onPress event on the TouchableHighlight element. It works when it is clicked again.

代码如下:

 return (
  <TouchableHighlight
      onPress={this.props.onPress}
      style={btnStyles}
      underlayColor="#a30000"
      activeOpacity={1}>
    <Text style={styles.buttonText}>{this.props.children}</Text>
  </TouchableHighlight>
);

这是我创建的按钮的链接:https://github.com/uiheros/react-native-redux-todo-list/blob/master/app/components/shared/Button.js

This is the link to the button I created: https://github.com/uiheros/react-native-redux-todo-list/blob/master/app/components/shared/Button.js

有人知道怎么解决吗?或者是什么导致了问题?

Does anyone know how to fix it? or what caused the problem?

目前这个问题在 ios 模拟器和 android 模拟器上都发生在我身上.我还没有在真实设备上测试过.

currently the problem happens to me on both ios simulator and android simulator. I have not tested in real devices yet.

推荐答案

我认为您正在使用模拟器来测试应用程序 (genymotion?) 同样的事情发生在我身上,我感到困惑但请放心,问题不在于你的应用程序,但模拟器或操作系统(有时第一次点击只是为了让模拟器成为焦点)我相信如果你在物理设备上尝试它会正常工作.

I think you are using an emulator to test the app (genymotion?) same thing happened to me and I got confused but rest assured that the issue is not with you app but emulator or operation system(sometimes the first click is just to bring the emulator into focus) I am positive that if you try it on the physical device it'll work properly.

希望对我有帮助

这篇关于React Native TouchableHighlight 忽略第一次点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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