首页 > 解决方案 > 为什么 hitSlop 在这个嵌套的 TouchableOpacity 组件中不起作用?

问题描述

我有一个嵌套的 TouchableOpacity 组件,如下所示:

  <View style={styles.mainTextContainer}>
    <Text>
      {mainText}
      <TouchableOpacity
        hitSlop={{top: Gutter, left: Gutter, bottom: Gutter, right: Gutter}}
        style={styles.icon}
        onPress={onPress}>
        {mainTextIcon}
      </TouchableOpacity>
    </Text>
  </View>

  // These are the corresponding styles
  icon: {
    justifyContent: "center",
  },
  mainTextContainer: {
    flexDirection: "row",
    flexWrap: "wrap",
    justifyContent: "flex-start",
  },

但是,似乎 hitSlop 道具不起作用。是因为它嵌套在 Text 组件中吗?

标签: react-nativetouchableopacity

解决方案


推荐阅读