react-native - TouchableOpacity 不起作用,因为它保留在另一个元素的 maskedView 下

标签 react-native

我有一张卡片 list 。每张卡片都有一个蒙版图像作为背景图像,并在其上覆盖 TouchableOpacity

问题:我只能触摸/单击最后一张牌。所有卡片都保留在列表中下一张卡片的掩码下。因此,最后一张卡片 TouchableOpacity 保持在顶部并且可以工作。

该问题仅出现在 IOS 上。我可以与 Android 上的所有卡片(模拟器和设备)进行交互。

卡片列表代码:

  <ScrollView style={styles.paddingBottom}>
  {props.jsonArray.map((item) => (
    <View style={styles.cardContainer} key={item.ar_id}>
      <Card 
        item={item} 
        listData={listData} 
        groupsArray={props.groupsArray} 
        setGroupsArray={props.setGroupsArray} 
        navigation={props.navigation}
        parameters={props.parameters}
        filterOptions={props.filterOptions} 
        costBoxWidth={costBoxWidth} 
        thumbnailWidth={thumbnailWidth} 
        mrRght={mrRght} 
        adInfoBase={adInfoBase} 
        adInfoWidth={adInfoWidth} 
        additional={additional} 
        cardWidth={cardWidth} 
      />
    </View>
  ))}
  </ScrollView>

卡片中的蒙版 View :

import MaskedView from '@react-native-masked-view/masked-view';

...

<MaskedView 
  style={styles.maskedView}
  maskElement={<View style={styles.opening} />}
  androidRenderingMode="software" 
>
  <View style={[ styles.sceneryContainer, {width: props.cardWidth} ]}>
    <Image source={sourceC} style={[ styles.rightImageSingle, { left: rightSingleImageLeft, top: rightSingleImageTop, width: rightSingleImageW } ]} />
    <Image style={styles.leftImage} source={sourceB} />
  </View>
</MaskedView>

<View style={[ styles.adInfoBox, {width: props.adInfoWidth, paddingLeft: props.mrRght} ]}>  ... some text ...  </View>

<TouchableOpacity style={{flex: 1}} onPress={() => {Linking.openURL(props.item["es_link"])}} />

cards

蓝色矩形是图像的边框。它们比卡片大。所以我使用了MaskedView

卡片中的 zIndex 顺序:

  • MaskedView(作为背景图片)位于最后面
  • 在中间查看(包含文本数据)
  • TouchableOpacity(用于导航详细信息页面)位于前面

第二张卡片的图像位于第一张卡片的前面,尽管它不可​​见。因此,第一张卡片的 TouchableOpacity 保留在后面且不可点击(在 iOS 上)。

最佳答案

我找到了解决方案。只需将 pointerEvents="none" 添加到 MaskedView Prop 就可以像魔术一样工作。它写在 docs 。谁知道呢,对吧。

关于react-native - TouchableOpacity 不起作用,因为它保留在另一个元素的 maskedView 下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71852500/

相关文章:

javascript - 当用户单击按钮时用 json 填充数组

react-native - 数据源属性不会从试剂传播到 React Native ListView 组件的渲染方法

xcode - 在iOS模拟器上运行React Native应用程序时,诊断过程的CPU负载很高

ios - 我无法在 ios Xcode 上运行我的 react-native 应用程序

ios - 允许用户在 React Native 中更改 App 图标

firebase - iOS 模拟器不支持此浏览器

react-native - react-native 组件的 flex 属性的 "default"值是多少?

ios - React Native、AwesomeProject、react-native run-ios : ** BUILD FAILED **

ios - 是否可以像谷歌地图一样使用第 3 方 reactjs 组件和 react-native?

react-native - 由于错误 "error: uncompiled PNG file passed as argument. Must be compiled first into .flat file.."无法生成 apk