gpt4 book ai didi

react-native - React Native 防止触摸冒泡到父元素

转载 作者:行者123 更新时间:2023-12-03 14:58:07 34 4
gpt4 key购买 nike

如果我想阻止 View 上的 onPress 事件组件传播到父级 Touchable对于以下 Sample组件,除了将 subview 包装在 Touchable 中之外,最好的选择是什么?请?

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

最佳答案

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

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

关于react-native - React Native 防止触摸冒泡到父元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46683832/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com