react-native - 反应原生样式表对象不是对象
问题描述
在 React Native 中,特别是在这个Card
组件中,我想以组件的样式传播两个对象<View>
,第一个对象是卡片,StyleSheet
第二个对象props.style
也StyleSheet
来自另一个组件,但是它不起作用,当我尝试console.log(styles.card)
它输出数字 19 并console.log(props.style)
输出数字 22
import React from "react";
import { View, StyleSheet } from "react-native";
const Card = (props) => {
console.log(styles.card) // This line output 19
console.log(props.style) // This line output 22
return (
<View style={{ ...styles.card, ...props.style }}>{props.children}</View>
);
};
const styles = StyleSheet.create({
card: {
shadowColor: "black",
shadowOffset: { width: 0, height: 2 },
shadowRadius: 6,
shadowOpacity: 0.26,
//elevation: 5, shadow for android
backgroundColor: "white",
padding: 20,
borderRadius: 10,
},
});
export default Card;
解决方案
推荐阅读
- node.js - Windows 节点服务未侦听端口
- javascript - 将 mocha 测试映射到 jira id
- flutter - 如何在 GridView 中编辑特定项目?
- javascript - 数字中的数字相乘 - 不包括零
- python - 在字符串格式键字段中添加其他字符
- c# - 连接字符串环境变量不在配置对象中,但可以使用 GetEnvironmentVariable 找到
- php - 来自 MySQL PDO 的回显数组
- google-bigquery - 是否可以覆盖 BigQuery 中的分区?
- javascript - 哪个版本的 ECMA 规范引入了提升?
- xamarin - 启动屏幕后 Xamarin.iOS 应用程序崩溃 - 条件“oti”未满足