可以触摸侧视图组件被检测到反应原生?

问题描述 投票:5回答:3

我的React本机应用程序屏幕具有几个文本输入的View组件。如何在View外的屏幕上检测到触摸?请帮忙。

谢谢

javascript reactjs mobile react-native
3个回答
3
投票

正如Andrew said:您可以使用TouchableWithoutFeedback包装View并添加onPress,您可以检测何时点击视图。

实现这一目标的另一种方法是对view的触摸事件做出响应。

 /* 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是在用户按下并移动按下位置时


1
投票

把你的View放在TouchableWithoutFeedback里面,展开TouchableWithoutFeedback全屏并添加onPress处理程序。

<TouchableWithoutFeedback 
  onPress={ /*handle tap outside of view*/ }
  style={ /* fullscreen styles */}
>
    <View>
     ...
    </View
</TouchableWithoutFeedback>

-2
投票

您可以尝试使用Modal来创建此行为。

单击输入字段时,将显示包含多个文本输入的模态。如果你在Modal外面点击它会隐藏。

© www.soinside.com 2019 - 2024. All rights reserved.