StyleSheetTypes.js
7.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule StyleSheetTypes
* @flow
* @format
*/
'use strict';
import AnimatedNode from 'AnimatedNode';
export opaque type StyleSheetStyle: number = number;
export type ColorValue = null | string;
export type DimensionValue = null | number | string | AnimatedNode;
export type LayoutStyle<+Dimension = DimensionValue> = {
+display?: 'none' | 'flex',
+width?: Dimension,
+height?: Dimension,
+bottom?: Dimension,
+end?: Dimension,
+left?: Dimension,
+right?: Dimension,
+start?: Dimension,
+top?: Dimension,
+minWidth?: Dimension,
+maxWidth?: Dimension,
+minHeight?: Dimension,
+maxHeight?: Dimension,
+margin?: Dimension,
+marginBottom?: Dimension,
+marginEnd?: Dimension,
+marginHorizontal?: Dimension,
+marginLeft?: Dimension,
+marginRight?: Dimension,
+marginStart?: Dimension,
+marginTop?: Dimension,
+marginVertical?: Dimension,
+padding?: Dimension,
+paddingBottom?: Dimension,
+paddingEnd?: Dimension,
+paddingHorizontal?: Dimension,
+paddingLeft?: Dimension,
+paddingRight?: Dimension,
+paddingStart?: Dimension,
+paddingTop?: Dimension,
+paddingVertical?: Dimension,
+borderWidth?: number,
+borderBottomWidth?: number,
+borderEndWidth?: number,
+borderLeftWidth?: number,
+borderRightWidth?: number,
+borderStartWidth?: number,
+borderTopWidth?: number,
+position?: 'absolute' | 'relative',
+flexDirection?: 'row' | 'row-reverse' | 'column' | 'column-reverse',
+flexWrap?: 'wrap' | 'nowrap',
+justifyContent?:
| 'flex-start'
| 'flex-end'
| 'center'
| 'space-between'
| 'space-around'
| 'space-evenly',
+alignItems?: 'flex-start' | 'flex-end' | 'center' | 'stretch' | 'baseline',
+alignSelf?:
| 'auto'
| 'flex-start'
| 'flex-end'
| 'center'
| 'stretch'
| 'baseline',
+alignContent?:
| 'flex-start'
| 'flex-end'
| 'center'
| 'stretch'
| 'space-between'
| 'space-around',
+overflow?: 'visible' | 'hidden' | 'scroll',
+flex?: number,
+flexGrow?: number,
+flexShrink?: number,
+flexBasis?: number | string,
+aspectRatio?: number,
+zIndex?: number,
+direction?: 'inherit' | 'ltr' | 'rtl',
};
export type TransformStyle = {
+transform?: $ReadOnlyArray<
| {+perspective: number | AnimatedNode}
| {+rotate: string}
| {+rotateX: string}
| {+rotateY: string}
| {+rotateZ: string}
| {+scale: number | AnimatedNode}
| {+scaleX: number | AnimatedNode}
| {+scaleY: number | AnimatedNode}
| {+translateX: number | AnimatedNode}
| {+translateY: number | AnimatedNode}
| {
+translate: [number | AnimatedNode, number | AnimatedNode] | AnimatedNode,
}
| {+skewX: string}
| {+skewY: string}
// TODO: what is the actual type it expects?
| {+matrix: $ReadOnlyArray<number | AnimatedNode> | AnimatedNode},
>,
};
export type ShadowStyle<+Color = ColorValue> = {
+shadowColor?: Color,
+shadowOffset?: {
+width?: number,
+height?: number,
},
+shadowOpacity?: number | AnimatedNode,
+shadowRadius?: number,
};
export type ViewStyle<+Dimension = DimensionValue, +Color = ColorValue> = {
...$Exact<LayoutStyle<Dimension>>,
...$Exact<ShadowStyle<Color>>,
...$Exact<TransformStyle>,
+backfaceVisibility?: 'visible' | 'hidden',
+backgroundColor?: Color,
+borderColor?: Color,
+borderBottomColor?: Color,
+borderEndColor?: Color,
+borderLeftColor?: Color,
+borderRightColor?: Color,
+borderStartColor?: Color,
+borderTopColor?: Color,
+borderRadius?: number,
+borderBottomEndRadius?: number,
+borderBottomLeftRadius?: number,
+borderBottomRightRadius?: number,
+borderBottomStartRadius?: number,
+borderTopEndRadius?: number,
+borderTopLeftRadius?: number,
+borderTopRightRadius?: number,
+borderTopStartRadius?: number,
+borderStyle?: 'solid' | 'dotted' | 'dashed',
+borderWidth?: number,
+borderBottomWidth?: number,
+borderEndWidth?: number,
+borderLeftWidth?: number,
+borderRightWidth?: number,
+borderStartWidth?: number,
+borderTopWidth?: number,
+opacity?: number | AnimatedNode,
+elevation?: number,
};
export type TextStyle<+Dimension = DimensionValue, +Color = ColorValue> = {
...$Exact<ViewStyle<Dimension, Color>>,
+color?: Color,
+fontFamily?: string,
+fontSize?: number,
+fontStyle?: 'normal' | 'italic',
+fontWeight?:
| 'normal'
| 'bold'
| '100'
| '200'
| '300'
| '400'
| '500'
| '600'
| '700'
| '800'
| '900',
+fontVariant?: $ReadOnlyArray<
| 'small-caps'
| 'oldstyle-nums'
| 'lining-nums'
| 'tabular-nums'
| 'proportional-nums',
>,
+textShadowOffset?: {+width?: number, +height?: number},
+textShadowRadius?: number,
+textShadowColor?: Color,
+letterSpacing?: number,
+lineHeight?: number,
+textAlign?: 'auto' | 'left' | 'right' | 'center' | 'justify',
+textAlignVertical?: 'auto' | 'top' | 'bottom' | 'center',
+includeFontPadding?: boolean,
+textDecorationLine?:
| 'none'
| 'underline'
| 'line-through'
| 'underline line-through',
+textDecorationStyle?: 'solid' | 'double' | 'dotted' | 'dashed',
+textDecorationColor?: Color,
+writingDirection?: 'auto' | 'ltr' | 'rtl',
};
export type ImageStyle<+Dimension = DimensionValue, +Color = ColorValue> = {
...$Exact<ViewStyle<Dimension, Color>>,
+resizeMode?: 'contain' | 'cover' | 'stretch' | 'center' | 'repeat',
+tintColor?: Color,
+overlayColor?: string,
};
export type Style<+Dimension = DimensionValue, +Color = ColorValue> = {
...$Exact<TextStyle<Dimension, Color>>,
+resizeMode?: 'contain' | 'cover' | 'stretch' | 'center' | 'repeat',
+tintColor?: Color,
+overlayColor?: string,
};
export type StyleProp<+T> =
| null
| void
| T
| StyleSheetStyle
| number
| false
| ''
| $ReadOnlyArray<StyleProp<T>>;
// export type ViewStyleProp = StyleProp<$Shape<ViewStyle<DimensionValue>>>;
// export type TextStyleProp = StyleProp<
// $Shape<TextStyle<DimensionValue, ColorValue>>,
// >;
// export type ImageStyleProp = StyleProp<
// $Shape<ImageStyle<DimensionValue, ColorValue>>,
// >;
export type StyleObj = StyleProp<$Shape<Style<DimensionValue, ColorValue>>>;
export type StyleValue = StyleObj;
export type ViewStyleProp = StyleObj;
export type TextStyleProp = StyleObj;
export type ImageStyleProp = StyleObj;
export type Styles = {
+[key: string]: $Shape<Style<DimensionValue, ColorValue>>,
};
export type StyleSheet<+S: Styles> = $ObjMap<S, (Object) => StyleSheetStyle>;
/*
Utility type get non-nullable types for specific style keys.
Useful when a component requires values for certain Style Keys.
So Instead:
```
type Props = {position: string};
```
You should use:
```
type Props = {position: TypeForStyleKey<'position'>};
```
This will correctly give you the type 'absolute' | 'relative' instead of the
weak type of just string;
*/
export type TypeForStyleKey<+key: $Keys<Style<>>> = $ElementType<Style<>, key>;