reactjs - 如何在TouchableOpacity标签中嵌入的按钮标签中触发onPress而不触发TouchableOpacity中的onPress
问题描述
我有一个视图在展开状态为真之前一直处于隐藏状态。按下 TouchableOpacity 时,它在 toggleView 中设置为 !expand。但是,当我单击按钮以添加到购物车和删除时,视图也会被切换。我怎样才能防止这种情况发生?
return (
<View style={styles.accordion}>
{/* Visible Bar which is pressed to expand hidden view */}
<TouchableOpacity onPress={toggleView} style={styles.collapsibleBar}>
<Icon name={expanded ? 'chevron-down-outline' : 'chevron-right-outline'} pack='eva' fill='grey' style={styles.icon} />
<View style={styles.itemHeader}>
<View style={styles.itemHeaderTextView}>
{/* HEADER STUFF */}
</View>
<View style={styles.buttonView}>
<Button onPress={() => addToCart()}>
Add to Cart
</Button>
<Button onPress={() => delete()}>
delete
</Button>
</View>
</View>
</TouchableOpacity>
{/* Hidden View */}
<View style={{ maxHeight: height, width: '100%', alignSelf: 'center' }}>
<>
{console.log(expanded)}
{expanded && ExpandedChild({
setHeight: setHeight,
date: props.cargoCharge.storageDueDate, tableData: props.cargoCharge.charges
})}
</>
</View>
</View>);
解决方案
TouchableOpacity
Ciao,试着像这样用 2 替换内部按钮。如果单击 internal TouchableOpacity
,事件将不会传播到 external TouchableOpacity
。
推荐阅读
- isabelle - 伊莎贝尔战术定义
- javascript - 未捕获的类型错误:无法设置 null javascript 的属性“src”
- aws-sdk - 尝试上传时发生 IllegalLocationConstraintException
- arrays - 在 React Native 中以文本形式呈现对象项
- python - 通过 Python/PyQt5 在 VLC 视频输出上显示文本
- python - 如何使用 pydoc 生成自己的代码文档?
- java - 带有水平滚动条的 JTable 不起作用
- c++ - 质数超过 600 万
- flutter - 在 MarqueeWidget 中将文本字段添加为子项会导致空白屏幕
- elasticsearch - 按嵌套对象的长度过滤查询。IE。min_child