禁用可触摸屏幕的子视图的可触摸性



我想禁用下面View的可触摸性。所以我不希望console.log在按下黄色方块时运行。我使用了pointerEvents,但它不起作用。我该怎么做?

import { Text, TouchableOpacity, View, } from "react-native"
import React from "react"

export default function Screen() {
return (
<TouchableOpacity
style={{ flex: 1, backgroundColor: "black" }}
onPress={() => console.log("pressed")}
>
<View
style={{ width: 100, height: 100, backgroundColor: "yellow" }}
pointerEvents="none"
>
<Text>React Native</Text>
</View>
</TouchableOpacity>
)
}

<TouchableOpacity
style={{ flex: 1, backgroundColor: "black" }}
onPress={() => console.log("pressed")} >
<TouchableOpacity activeOpacity={1}>
<View
style={{ width: 100, height: 100, backgroundColor: "yellow" }}>
<Text>React Native</Text>
</View>
</TouchableOpacity>
</TouchableOpacity>

最新更新