react-native - 如何通过单击另一个组件的按钮使视图在一个组件中可见?
问题描述
我有两个组件 组件 A 有一个默认隐藏按钮,另一个组件 B 有搜索按钮 当我单击组件 B 中的按钮时,如何使组件 A 中的按钮可见,我在 A 中导入组件 B 如何实现上述功能?
解决方案
当您激活一个按钮时,有很多方法可以浮动其他组件。
您可以更改状态值使其浮动,或者您可以通过键值传递值以接收数据并执行按钮,如下例所示。
例子.js
<TouchableOpacity
onPress={() => this.getItems()}
activeOpacity={0.5}
style={styles.btn}
textStyle={styles.txt}
>Get Products ({productList.length})</TouchableOpacity>
{
productList.map((product, i) => {
return (
<View key={i} style={{
flexDirection: 'column',
}}>
<Text style={{
marginTop: 20,
fontSize: 12,
color: 'black',
minHeight: 100,
alignSelf: 'center',
paddingHorizontal: 20,
}} >{JSON.stringify(product)}</Text>
<TouchableOpacity
onPress={() => this.buyItem(product.productId)}
activeOpacity={0.5}
style={styles.btn}
textStyle={styles.txt}
>Buy Above Product</TouchableOpacity>
</View>
);
})
}
推荐阅读
- excel - 函数 Dir() 无法正常工作:错误代码 5:无效的参数或过程调用
- primeng - PrimeNG Spinner 中的 DecimalSeparator 不起作用
- android - 我不去下一个活动?
- jquery - 如何禁用未绑定事件
- react-router - 如何反应路线路径一/二/三?
- java - 如何将文件/位图上传到 Cloud Firestore?
- json - 确定用于简单时间跟踪应用程序的数据模型
- vba - 格式化 SentOn 以仅显示日期
- c# - 将 Null-Propagation 运算符与 null-coalescing-operator 一起使用以引发空异常
- amazon-web-services - 使用正确的时间戳将 log4j2 JSON 格式的日志文件上传到 AWS CloudWatch