├── .gitignore
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | # kdiff3 ignore
2 | *.orig
3 |
4 | # maven ignore
5 | target/
6 |
7 | # eclipse ignore
8 | .settings/
9 | .project
10 | .classpath
11 |
12 | # idea ignore
13 | .idea/
14 | *.ipr
15 | *.iml
16 | *.iws
17 |
18 | # temp ignore
19 | *.log
20 | *.cache
21 | *.diff
22 | *.patch
23 | *.tmp
24 |
25 | # system ignore
26 | .DS_Store
27 | Thumbs.db
28 |
29 | # package ignore (optional)
30 | # *.jar
31 | # *.war
32 | # *.zip
33 | # *.tar
34 | # *.tar.gz
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Joy Du
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React-Native 样式指南
2 |
3 | `React-Native` 的样式基本上是实现了 `CSS` 的一个子集,并且属性名不完全一致,所以当你开始在编写 `React-Native` 之前,可以先简要了解一下。
4 |
5 | ## 当前对应 RN 版本
6 |
7 | 0.44
8 |
9 | ## 目录
10 |
11 | * [Properties 属性](#user-content-properties)
12 | * [Text 文本](#user-content-text)
13 | * [Dimension 尺寸](#user-content-dimension)
14 | * [Positioning 定位](#user-content-positioning)
15 | * [Margin 外部白](#user-content-margin)
16 | * [Padding 内补白](#user-content-padding)
17 | * [Border 边框](#user-content-border)
18 | * [Background 背景](#user-content-background)
19 | * [Transform 转换](#user-content-transform)
20 | * [Flexbox 弹性盒](#user-content-flexbox)
21 | * [Other 其他](#user-content-other)
22 | * [Values 取值](#user-content-values)
23 | * [Color 颜色](#user-content-color)
24 | * [Number 数值](#user-content-number)
25 | * [Units 单位](#user-content-units)
26 | * [Pt 点](#user-content-pt)
27 | * [PixelRatio 像素密度](#user-content-pixelratio)
28 |
29 |
30 |
31 | ## Properties 属性
32 |
33 |
34 | ### Text 文本(18)
35 | 属性名 | 取值 | 描述
36 | ---|---|---
37 | color | [<color>](#user-content-color) | 对应 `CSS` [color](http://css.doyoe.com/properties/color/color.htm) 属性
38 | fontFamily | string | 对应 `CSS` [font-family](http://css.doyoe.com/properties/font/font-family.htm) 属性
39 | fontSize | [<number>](#user-content-number) | 对应 `CSS` [font-size](http://css.doyoe.com/properties/font/font-size.htm) 属性
40 | fontStyle | `normal`, `italic` | 对应 `CSS` [font-style](http://css.doyoe.com/properties/font/font-style.htm) 属性,但阉割了 `oblique` 取值
41 | fontWeight | `normal`, `bold` `100~900` | 对应 `CSS` [font-weight](http://css.doyoe.com/properties/font/font-weight.htm) 属性,但阉割了 `bolder, lighter` 取值
42 | lineHeight | [<number>](#user-content-number) | 对应 `CSS` [line-height](http://css.doyoe.com/properties/text/line-height.htm) 属性
43 | textAlign | `auto`, `left`, `right`, `center`, `justify``iOS` | 对应 `CSS` [text-align](http://css.doyoe.com/properties/text/text-align.htm) 属性,但增加了 `auto` 取值。当取值为 `justify` 时,在 `Android` 上会变为 `left`
44 | textDecorationLine | `none`, `underline`, `line-through`, `underline line-through` | 对应 `CSS` [text-decoration-line](http://css.doyoe.com/properties/text-decoration/text-decoration-line.htm) 属性,但阉割了 `overline`, `blink` 取值
45 | textShadowColor | [<color>](#user-content-color) | 对应 `CSS` [text-shadow](http://css.doyoe.com/properties/text-decoration/text-shadow.htm) 属性中的颜色定义
46 | textShadowOffset | {
width:[<number>](#user-content-number),
height:[<number>](#user-content-number)
} | 对应 `CSS` [text-shadow](http://css.doyoe.com/properties/text-decoration/text-shadow.htm) 属性中的阴影偏移定义
47 | textShadowRadius | [<number>](#user-content-number) | 在 `CSS` 中,阴影的圆角大小取决于元素的圆角定义,不需要额外定义
48 | includeFontPadding
`Android` | [<bool>](#user-content-bool) | Android在默认情况下会为文字额外保留一些padding,以便留出空间摆放上标或是下标的文字。对于某些字体来说,这些额外的padding可能会导致文字难以垂直居中。如果你把textAlignVertical设置为center之后,文字看起来依然不在正中间,那么可以尝试将本属性设置为false
49 | textAlignVertical
`Android` | `auto`, `top`, `bottom`, `center` | 对应 `CSS` [vertical-align](http://css.doyoe.com/properties/text/vertical-align.htm) 属性,增加了 `auto` 取值,`center` 取代了 `middle`,并阉割了 `baseline, sub` 等值
50 | fontVariant
`iOS` | `small-caps`, `oldstyle-nums`, `lining-nums`, `tabular-nums`, `proportional-nums` | 对应 `CSS` [font-variant](http://css.doyoe.com/properties/font/font-variant.htm) 属性,但取值更丰富
51 | letterSpacing
`iOS` | [<number>](#user-content-number) | 对应 `CSS` [letter-spacing](http://css.doyoe.com/properties/text/letter-spacing.htm) 属性
52 | textDecorationColor
`iOS` | [<color>](#user-content-color) | 对应 `CSS` [text-decoration-color](http://css.doyoe.com/properties/text-decoration/text-decoration-color.htm) 属性
53 | textDecorationStyle
`iOS` | `solid`, `double`, `dotted`, `dashed` | 对应 `CSS` [text-decoration-style](http://css.doyoe.com/properties/text-decoration/text-decoration-style.htm) 属性,但阉割了 `wavy` 取值
54 | writingDirection
`iOS` | `auto`, `ltr`, `rtl` | 对应 `CSS` [direction](http://css.doyoe.com/properties/writing-modes/direction.htm) 属性,增加了 `auto` 取值
55 |
56 |
57 | ### Dimension 尺寸(6)
58 | 属性名 | 取值 | 描述
59 | ---|---|---
60 | width | [<number>](#user-content-number) | 对应 `CSS` [width](http://css.doyoe.com/properties/dimension/width.htm) 属性
61 | minWidth | [<number>](#user-content-number) | 对应 `CSS` [min-width](http://css.doyoe.com/properties/dimension/min-width.htm) 属性
62 | maxWidth | [<number>](#user-content-number) | 对应 `CSS` [max-width](http://css.doyoe.com/properties/dimension/max-width.htm) 属性
63 | height | [<number>](#user-content-number) | 对应 `CSS` [height](http://css.doyoe.com/properties/dimension/height.htm) 属性
64 | minHeight | [<number>](#user-content-number) | 对应 `CSS` [min-height](http://css.doyoe.com/properties/dimension/min-height.htm) 属性
65 | maxHeight | [<number>](#user-content-number) | 对应 `CSS` [max-height](http://css.doyoe.com/properties/dimension/max-height.htm) 属性
66 |
67 |
68 | ### Positioning 定位(6)
69 | 属性名 | 取值 | 描述
70 | ---|---|---
71 | position | `absolute`, `relative` | 对应 `CSS` [position](http://css.doyoe.com/properties/positioning/position.htm) 属性,但阉割了 `static, fixed` 取值
72 | top | [<number>](#user-content-number) | 对应 `CSS` [top](http://css.doyoe.com/properties/positioning/top.htm) 属性
73 | right | [<number>](#user-content-number) | 对应 `CSS` [right](http://css.doyoe.com/properties/positioning/right.htm) 属性
74 | bottom | [<number>](#user-content-number) | 对应 `CSS` [bottom](http://css.doyoe.com/properties/positioning/bottom.htm) 属性
75 | left | [<number>](#user-content-number) | 对应 `CSS` [left](http://css.doyoe.com/properties/positioning/left.htm) 属性
76 | zIndex | [<number>](#user-content-number) | 对应 `CSS` [z-index](http://css.doyoe.com/properties/positioning/z-index.htm) 属性
77 |
78 |
79 | ### Margin 外部白(7)
80 | 属性名 | 取值 | 描述
81 | ---|---|---
82 | margin | [<number>](#user-content-number) | 对应 `CSS` [margin](http://css.doyoe.com/properties/margin/margin.htm) 属性,不同的是,它只能定义一个参数,如需分别定义`上、右、下、左`4个方位的外补白,可以通过下面的单向外部白属性
83 | marginHorizontal | [<number>](#user-content-number) | 无对应的 `CSS` 属性。其效果相当于同时设置 `marginRight` 和 `marginLeft`
84 | marginVertical | [<number>](#user-content-number) | 无对应的 `CSS` 属性。其效果相当于同时设置 `marginTop` 和 `marginBottom`
85 | marginTop | [<number>](#user-content-number) | 对应 `CSS` [margin-top](http://css.doyoe.com/properties/margin/margin-top.htm) 属性
86 | marginRight | [<number>](#user-content-number) | 对应 `CSS` [margin-right](http://css.doyoe.com/properties/margin/margin-right.htm) 属性
87 | marginBottom | [<number>](#user-content-number) | 对应 `CSS` [margin-bottom](http://css.doyoe.com/properties/margin/margin-bottom.htm) 属性
88 | marginLeft | [<number>](#user-content-number) | 对应 `CSS` [margin-left](http://css.doyoe.com/properties/margin/margin-left.htm) 属性
89 |
90 |
91 | ### Padding 内部白(7)
92 | 属性名 | 取值 | 描述
93 | ---|---|---
94 | padding | [<number>](#user-content-number) | 对应 `CSS` [padding](http://css.doyoe.com/properties/padding/padding.htm) 属性,不同的是,它只能定义一个参数,如需分别定义`上、右、下、左`4个方位的内补白,可以通过下面的单向内部白属性
95 | paddingHorizontal | [<number>](#user-content-number) | 无对应的 `CSS` 属性。其效果相当于同时设置 `paddingRight` 和 `paddingLeft`
96 | paddingVertical | [<number>](#user-content-number) | 无对应的 `CSS` 属性。其效果相当于同时设置 `paddingTop` 和 `paddingBottom`
97 | paddingTop | [<number>](#user-content-number) | 对应 `CSS` [padding-top](http://css.doyoe.com/properties/padding/padding-top.htm) 属性
98 | paddingRight | [<number>](#user-content-number) | 对应 `CSS` [padding-right](http://css.doyoe.com/properties/padding/padding-right.htm) 属性
99 | paddingBottom | [<number>](#user-content-number) | 对应 `CSS` [padding-bottom](http://css.doyoe.com/properties/padding/padding-bottom.htm) 属性
100 | paddingLeft | [<number>](#user-content-number) | 对应 `CSS` [padding-left](http://css.doyoe.com/properties/padding/padding-left.htm) 属性
101 |
102 |
103 | ### Border 边框(20)
104 | 属性名 | 取值 | 描述
105 | ---|---|---
106 | borderStyle | `solid`, `dotted`, `dashed` | 对应 `CSS` `border-style` 属性,但阉割了 `none, hidden, double, groove, ridge, inset, outset` 取值,且无方向分拆属性
107 | borderWidth | [<number>](#user-content-number) | 对应 `CSS` `border-width` 属性
108 | borderTopWidth | [<number>](#user-content-number) | 对应 `CSS` `border-top-width` 属性
109 | borderRightWidth | [<number>](#user-content-number) | 对应 `CSS` `border-right-width` 属性
110 | borderBottomWidth | [<number>](#user-content-number) | 对应 `CSS` `border-bottom-width` 属性
111 | borderLeftWidth | [<number>](#user-content-number) | 对应 `CSS` `border-left-width` 属性
112 | borderColor | [<color>](#user-content-color) | 对应 `CSS` `border-color` 属性
113 | borderTopColor | [<color>](#user-content-color) | 对应 `CSS` `border-top-color` 属性
114 | borderRightColor | [<color>](#user-content-color) | 对应 `CSS` `border-right-color` 属性
115 | borderBottomColor | [<color>](#user-content-color) | 对应 `CSS` `border-bottom-color` 属性
116 | borderLeftColor | [<color>](#user-content-color) | 对应 `CSS` `border-left-color` 属性
117 | borderRadius | [<number>](#user-content-number) | 对应 `CSS` `border-radius` 属性
118 | borderTopLeftRadius | [<number>](#user-content-number) | 对应 `CSS` `border-top-left-radius` 属性
119 | borderTopRightRadius | [<number>](#user-content-number) | 对应 `CSS` `border-top-right-radius` 属性
120 | borderBottomLeftRadius | [<number>](#user-content-number) | 对应 `CSS` `border-bottom-left-radius` 属性
121 | borderBottomRightRadius | [<number>](#user-content-number) | 对应 `CSS` `border-bottom-right-radius` 属性
122 | shadowColor | [<color>](#user-content-color) | 对应 `CSS` [box-shadow](http://css.doyoe.com/properties/border/box-shadow.htm) 属性中的颜色定义
123 | shadowOffset | {
width: [<number>](#user-content-number),
height: [<number>](#user-content-number)
} | 对应 `CSS` [box-shadow](http://css.doyoe.com/properties/border/box-shadow.htm) 属性中的阴影偏移定义
124 | shadowRadius | [<number>](#user-content-number) | 在 `CSS` 中,阴影的圆角大小取决于元素的圆角定义,不需要额外定义
125 | shadowOpacity | [<number>](#user-content-number) | 对应 `CSS` [box-shadow](http://css.doyoe.com/properties/border/box-shadow.htm) 属性中的阴影透明度定义
126 |
127 |
128 | ### Background 背景(1)
129 | 属性名 | 取值 | 描述
130 | ---|---|---
131 | backgroundColor | [<color>](#user-content-color) | 对应 `CSS` `background-color` 属性
132 |
133 |
134 | ### Transform 转换(3)
135 | 属性名 | 取值 | 描述
136 | ---|---|---
137 | transform | `[{perspective: number}, {rotate: string}, {rotateX: string}, {rotateY: string}, {rotateZ: string}, {scale: number}, {scaleX: number}, {scaleY: number}, {translateX: number}, {translateY: number}, {skewX: string}, {skewY: string}]` | 对应 `CSS` `transform` 属性
138 | transformMatrix | `TransformMatrixPropType` | 类似于 `CSS` 中 `transform` 属性的 `matrix()` 和 `matrix3d()` 函数
139 | backfaceVisibility | `visible`, `hidden` | 对应 `CSS` `backface-visibility` 属性
140 |
141 |
142 | ### Flexbox 弹性盒(9)
143 | 属性名 | 取值 | 描述
144 | ---|---|---
145 | flex | [<number>](#user-content-number) | 对应 `CSS` `flex` 属性,但只能为整数值
146 | flexGrow | [<number>](#user-content-number) | 对应 `CSS` `flex-grow` 属性
147 | flexShrink | [<number>](#user-content-number) | 对应 `CSS` `flex-shrink` 属性
148 | flexBasis | [<number>](#user-content-number) | 对应 `CSS` `flex-basis` 属性
149 | flexDirection | `row`, `row-reverse`, `column`, `column-reverse` | 对应 `CSS` `flex-direction` 属性
150 | flexWrap | `wrap`, `nowrap` | 对应 `CSS` `flex-wrap` 属性,但阉割了 `wrap-reverse` 取值
151 | justifyContent | `flex-start`, `flex-end`, `center`, `space-between`, `space-around` | 对应 `CSS` `justify-content` 属性,但阉割了 `stretch` 取值。
152 | alignItems | `flex-start`, `flex-end`, `center`, `stretch` | 对应 `CSS` `align-items` 属性,但阉割了 `baseline` 取值。
153 | alignSelf | `auto`, `flex-start`, `flex-end`, `center`, `stretch` | 对应 `CSS` `align-self` 属性,但阉割了 `baseline` 取值
154 |
155 |
156 | ### Other 其他
157 | 属性名 | 取值 | 描述
158 | ---|---|---
159 | opacity | [<number>](#user-content-number) | 对应 `CSS` `opacity` 属性
160 | overflow | `visible`, `hidden`, `scroll` | 对应 `CSS` `overflow` 属性,但阉割了 `auto` 取值
161 | elevation
`Android` | [<number>](#user-content-number) | `CSS`中没有对应的属性,只在 `Android5.0+` 上有效
162 | resizeMode | `cover`, `contain`, `stretch` | `CSS`中没有对应的属性,可以参考 `background-size` 属性
163 | overlayColor
`Android` | string | `CSS`中没有对应的属性,当图像有圆角时,将角落都充满一种颜色
164 | tintColor
`iOS` | [<color>](#user-content-color) | `CSS`中没有对应的属性,`iOS` 图像上特殊的色彩,改变不透明像素的颜色
165 |
166 |
167 |
168 | ## Valuse 取值
169 |
170 |
171 | ### Color 颜色
172 |
173 | `React Native` 支持了 `CSS` 中大部分的颜色类型:
174 |
175 | * `#f00` (#rgb)
176 | * `#f00c` (#rgba):`CSS` 中无对应的值
177 | * `#ff0000` (#rrggbb)
178 | * `#ff0000cc` (#rrggbbaa):`CSS` 中无对应的值
179 | * `rgb(255, 0, 0)`
180 | * `rgba(255, 0, 0, 0.9)`
181 | * `hsl(360, 100%, 100%)`
182 | * `hsla(360, 100%, 100%, 0.9)`
183 | * `transparent`
184 | * `0xff00ff00` (0xrrggbbaa):`CSS` 中无对应的值
185 | * `Color Name`:支持了 [基本颜色关键字](http://css.doyoe.com/appendix/color-keywords.htm#basic) 和 [拓展颜色关键字](http://css.doyoe.com/appendix/color-keywords.htm#extended),但不支持 [28个系统颜色](http://css.doyoe.com/appendix/color-keywords.htm#system);
186 |
187 |
188 | ### Number 数值
189 |
190 | 在 `React-Native` 中,目前仅支持 `Number` 这一种长度取值。默认缺省了 `pt` 单位,详细请看 [Units 单位](#user-content-units) 部分。
191 |
192 |
193 | ## Units 单位
194 |
195 |
196 | ### Pt 点
197 |
198 | 在 `React-Native` 中,并不支持百分比单位,目前只支持一种单位,即 `pt` 绝对长度单位,同时,你在定义时不需要加单位,例如:
199 |
200 | ```
201 |
202 | ```
203 |
204 | ```
205 | var styles = StyleSheet.create({
206 | box: {
207 | width: 100,
208 | height: 50
209 | }
210 | });
211 | ```
212 |
213 |
214 | ## PixelRatio 像素密度
215 |
216 | 在 `React-Native` 中,访问设备像素密度的方法由 `PixelRatio` 类提供。
217 |
218 | 我们的应用通常都会运行在不同的设备上,并且这些设备的像素密度很有可能各不相同。这会造成一个现象就是:
219 |
220 | * 定义了元素的边框为 `1像素`,而实际上在不同像素密度的设备上结果不一样,比如:iPhone6 显示为 `2像素`,iPhone6 Plus 显示为 `3像素`;
221 | * 对于一个图片来讲,因为设备的像素密度不同,它也需要对应不同尺寸的规则,以防止图片过小变得模糊;
222 |
223 | ### 根据像素密度指定边框厚度
224 |
225 | 出于对产品体验的一致性,我们会要求不论是在哪种设备上,其边框厚度都应该是相同的。一个取得物理上的相同边框厚度的好方法就是用逻辑尺寸除以像素密度比:
226 |
227 | ```
228 | var styles = StyleSheet.create({
229 | box: {
230 | borderWidth: 1 / PixelRatio.get(),
231 | borderStyle: solid
232 | }
233 | });
234 | ```
235 |
236 | 上述代码将保证你的应用在所有的设备上(像素密度),都获得 `1像素` 的边框厚度。`PixelRatio` 通过 `get()` 方法来返回设备的像素密度。
237 |
238 | 未完待续。。。
--------------------------------------------------------------------------------