reactjs - 阴影不会出现在本机反应中
问题描述
我想给我的卡片组件添加一个阴影,但它既没有出现 ios 也没有出现 android,这是什么问题?
function Card(props) {
return (
<View style={styles.box}>
<View style={styles.inner}>{props.children}</View> {// Takes an image}
</View>
);
}
const styles = StyleSheet.create({
box: {
width: "50%",
height: "50%",
padding: 15,
shadowColor: "#000", {// the shadow styles for android and ios}
shadowOffset: {
width: 0,
height: 6,
},
shadowOpacity: 0.37,
shadowRadius: 7.49,
elevation: 12,
},
inner: {
flex: 1,
backgroundColor: "#eee",
alignItems: "center",
justifyContent: "center",
},
});
注意:它需要一张图片,图片覆盖了我的整个卡片组件
另外这里是父组件样式:
container: {
width: "100%",
height: "85%",
padding: 10,
flexDirection: "row",
flexWrap: "wrap",
flex: 1,
alignItems: "center",
justifyContent: "center",
},
imageStyle: {
resizeMode: "stretch",
width: "100%",
height: "100%",
borderRadius: 10,
overflow: "hidden",
},
父组件示例:
<View style={styles.container}>
<Card>
<Image
style={styles.imageStyle}
source={require("../assets/games/Among-us.png")}
/>
</Card>
</View>
解决方案
问题在于您没有将 backgroundColor 应用于您的styles.box
更新您的styles.box以匹配此:
box: {
width: "50%",
height: "50%",
padding: 15,
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 6,
},
shadowOpacity: 0.37,
shadowRadius: 7.49,
elevation: 12,
backgroundColor: '#ffffff'
}
你会看到你的影子。
这是已知的错误,您可以在此处阅读Android - 如果没有 backgroundColor,海拔样式属性将不起作用
推荐阅读
- flutter - Map 的 containsKey() 在序列化对象上失败
- c++ - 为什么对整数的右值引用是合法的
- html - Ajax html 响应中断
- lua - 我在 roblox 中编码 lua 并且发生了一个错误可能有人向我解释这意味着什么
- javascript - 在 reduce 函数中执行聚合函数
- mongodb - MongoTransactionException:查询失败,错误代码 251
- shell - 检查文件是否存在于另一个位置,然后根据 Unix 中的条件复制文件
- angular - 测试在订阅中设置的属性的值
- python - 如何使 tkinter 文本框类型超出框架?
- sql - 分组和旋转