按下时 TouchableOpacity 不起作用React-Native

问题描述

我有一个 TouchableOpacity 组件,它在按下时什么也不做。我检查了解决方案,一切都很好,我正确地导入了组件,但我没有指定绝对位置。

注意:hp 和 wp 来自一个库,其中 wp(100) 是屏幕宽度的 100%

这是我的实现:

<View style={styles.container}>
    <View style={styles.header}>
      <TouchableOpacity
        style={styles.icon}
        onPress={() => console.log('dismissed')}
      >
        <SimpleArrowLeft />
      </TouchableOpacity>

      <Text style={styles.title}>{getMessageByKey('uploadRecipe.selectMedia')}</Text>
    </View>
    .
    .
    .

以及样式:

container: {
    backgroundColor: Colors.white,width: wp(100),height: hp(100),left: wp(-5),},header: {
    paddingTop: wp(5),height: hp(7),flexDirection: 'row',// alignItems: 'center',icon: {
    height: hp(3.5),width: hp(3.5),

解决方法

解决了: 我在样式中的 postion: 'relative' 的样式中使用了 TouchableOpacity。所以解决方案是将 TouchableOpacity 放在父视图的末尾并且它是固定的