10000 react-native中的样式 · Issue #34 · zhouzhongyuan/qa · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
react-native中的样式 #34
Closed
Closed
@zhouzhongyuan

Description

@zhouzhongyuan

1.简介

  • React Native中定义样式,可以使用Object,也可以使用StyleSheet.create
  • 默认推荐使用StyleSheet.create

2.StyleSheet.create优点

  • 通过把value转为纯数字(数字哪儿来的,转化得到的),引用内部表格(转化时生成的)。
  • 保证value的immutable和opaque(不透明)

3.使用时的注意点

  • 把定义放在文件末尾。保证被创建一次,而不是每次render创建一次。官方示例
    【疑问】难道放在顶部就会每次创建?? 我认为是放在顶部效果一样,只要放在Class外面。

4.合并规则

用法类似<View style={[styles.base, styles.background]} />,与Object.assign作用相同。

  • 右边的覆盖左边的
  • falsy values like false, undefined and null will be ignored. (为什么忽略呢,因为style根本就没有这种value啊)

5.样式大全

react-native-styling-cheat-sheet

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0