【发布时间】:2019-03-24 03:15:34
【问题描述】:
我有一个组件 Logo,我试图在其中应用宽度和高度:
import styledNative from "styled-components/native";
import {Image, View} from "react-native"
import companyIcon from "../svg/companyIcon.svg";
const Logo = () => (
<Image source={{uri: companyIcon}} />;
);
const StyledLogo = styledNative(Logo)`
width: 48px;
height: 48px;
`;
const Header = () => {
return (
<View>
<StyledLogo />
</View>
);
};
这给我们留下了一个不可见的徽标,宽度为 0。样式组件文档似乎建议使用传入的 className 属性 (https://www.styled-components.com/docs/advanced#existing-css),但这似乎适用于标准样式组件,而不是 react- native / react-native-web 实现,因为它只是没有传递给我的组件。当我检查传递的 Logo 道具(通过控制台记录它们)时,有 is 一个样式对象,但这似乎不是我可以使用的任何东西,并且在样式中没有太多提及它组件文档:
style: Array(2)
0: 91
1: undefined
length: 2
所以我不太确定如何处理它。 styled-components如何给组件设置样式?
【问题讨论】:
标签: react-native styled-components