【问题标题】:React Native prevent touch bubbling to parent elementsReact Native 防止触摸冒泡到父元素
【发布时间】:2017-10-11 08:49:40
【问题描述】:

如果我想阻止 View 组件上的 onPress 事件传播到父 Touchable 以获取以下 Sample 组件,除了将子视图包装在 Touchable 中之外,最好的选择是什么?

export default function Sample (): Element<*> {
  return(
    <TouchableOpacity>
      <View>
        <Text>Sample</Text>
      </View>
    </TouchableOpacity>
  );
}

【问题讨论】:

标签: react-native react-native-android react-native-ios touchableopacity touchablehighlight


【解决方案1】:

在我的情况下,我只是将 View 放在另一个 TouchableOpacity 中(将 activeOpacity 设置为 1 以阻止任何图形效果):

export default function Sample (): Element<*> {
  return(
    <TouchableOpacity>
      <TouchableOpacity activeOpacity={1}>
        <View>
          <Text>Sample</Text>
        </View>
      </TouchableOpacity>
    </TouchableOpacity>
  );
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-03
    • 2010-11-30
    • 2016-12-02
    • 2023-03-24
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多