为了让QAP/Rax 保持高性能渲染,样式具有以下几个与传统web前端css 不同的地方:
a)样式使用js定义
b)不能被继承
c)布局仅支持flexbox
d)样式不能针对所有标签元件生效
<View style={styles.container}> <Text>hello world</Text> </View> const styles = { container: { backgroundColor: 'grey', width: '750rem' } };
多个样式叠加
<View style={[styles.container,styles.new,{backgroundColor:'yellow'}]}> <Text>hello world</Text> </View> const styles = { container: { backgroundColor: 'grey', width: '750rem' }, new:{ borderWidth:'1rem', borderStyle:'solid', borderColor:'#ffffff' } };
上述样式数组merge 为样式 Object 后作为View的最终样式渲染。
受限于Native,QAP/Rax 对样式的支持只是传统css的一个子集。请查看 通用样式
1rem = document.documentElement.clientWidth / 750
我们推荐视觉稿产出宽度为750px,在这样的前提下,**我们在 750 的设计稿上量到的数值是abc,那么 width : ‘abcrem’ 就是我们需要映射到元素上的尺寸**。不加单位的width: abc
写法也是可以的,在Rx 框架中默认被解析为 width: abc rem
为了降低使用上的不适感,我们做了样式语法糖工具 - rx-css-loader,具体参考下一章节
在 Rx 中,Flexbox 是默认且唯一的样式模型,所以你不需要手动为元素添加 display: flex; 属性。记不住flexbox 属性值和value? 我们为你提供速查样式库 https://g.alicdn.com/nuke/doc-case/0.0.1/flex.html