可以在react native中检测出View Component的侧面吗? [英] Can touch out side a View Component be detected in react native?

查看:91
本文介绍了可以在react native中检测出View Component的侧面吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的React本机应用程序"屏幕的视图"组件几乎没有文字输入.如何在该视图之外的屏幕上检测到触摸?请帮忙.

My React native application screen has View component with few text inputs. How can touch be detected on screen outside that View? Please help.

谢谢

推荐答案

如安德鲁所说:您可以包装视图使用TouchableWithoutFeedback并添加onPress,您可以检测到何时点击视图.

As Andrew said: You can wrap your View with TouchableWithoutFeedback and adding a onPress you can detect when the view is tapped.

另一种实现方法是从查看.

 /* Methods that handled the events */
handlePressIn(event) {
  // Do stuff when the view is touched
}

handlePressOut(event) {
    // Do stuff when the the touch event is finished
}

...

    <View
      onStartShouldSetResponder={(evt) => true}
      onMoveShouldSetResponder={(evt) => true}
      onResponderGrant={this.handlePressIn}
      onResponderMove={this.handlePressIn}
      onResponderRelease={this.handlePressOut}
    >
         ...
    </View>

Grant和move的区别在于Grant是在用户按下时,而Move是在用户按下并移动按下位置时

The difference between Grant and move is that Grant is just when the user press, and Move is when the user is pressing and moving the position of the press

这篇关于可以在react native中检测出View Component的侧面吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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