[英]How can I add CSS files into react-native app without using styleSheet native elements
我需要将纯CSS
文件添加到react-native android和ios应用中。 如何不使用styleSheet本机元素来解决此问题?
body {
margin: 25px;
background-color: rgb(240,240,240);
font-family: arial, sans-serif;
font-size: 14px;
}
h1 {
font-size: 35px;
font-weight: normal;
margin-top: 5px;
}
是的你可以,
尝试使用CSS到本机
将CSS文本转换为React Native样式表对象。
font-size: 18px;
line-height: 24px;
color: red;
至
{
fontSize: 18,
lineHeight: 24,
color: 'red',
}
将所有类似数字的值转换为数字,并将类似字符串的转换为字符串。
import transform from 'css-to-react-native';
// or const transform = require('css-to-react-native').default;
transform([
['font', 'bold 14px/16px "Helvetica"'],
['margin', '5px 7px 2px'],
['border-left-width', '5px'],
]); // => { fontFamily: 'Helvetica', ... }
然后,您可以使用css编写组件样式的代码。
const Body = styled.body`
margin: 25px;
background-color: rgb(240,240,240);
font-family: arial, sans-serif;
font-size: 14px;
`;
const Header = styled.h1`
font-size: 35px;
font-weight: normal;
margin-top: 5px;
`;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.