Skip to content

Commit b6c7e55

Browse files
elicwhitefacebook-github-bot
authored andcommitted
Using ReadOnly and Exact types for StyleSheet
Summary: There are a few more things that need to be tightened up but they cause *tons* of errors in FBSource and require more investigation before we can change them. Reviewed By: sahrens Differential Revision: D7160522 fbshipit-source-id: 17167efd80fd6c3bac5a055d2ab58b3b251c1b8b
1 parent b98bf1e commit b6c7e55

File tree

1 file changed

+142
-137
lines changed

1 file changed

+142
-137
lines changed

Libraries/StyleSheet/StyleSheetTypes.js

+142-137
Original file line numberDiff line numberDiff line change
@@ -18,153 +18,155 @@ export opaque type StyleSheetStyle: number = number;
1818
export type ColorValue = null | string;
1919
export type DimensionValue = null | number | string | AnimatedNode;
2020

21-
export type LayoutStyle = {
22-
+display?: 'none' | 'flex',
23-
+width?: DimensionValue,
24-
+height?: DimensionValue,
25-
+bottom?: DimensionValue,
26-
+end?: DimensionValue,
27-
+left?: DimensionValue,
28-
+right?: DimensionValue,
29-
+start?: DimensionValue,
30-
+top?: DimensionValue,
31-
+minWidth?: DimensionValue,
32-
+maxWidth?: DimensionValue,
33-
+minHeight?: DimensionValue,
34-
+maxHeight?: DimensionValue,
35-
+margin?: DimensionValue,
36-
+marginBottom?: DimensionValue,
37-
+marginEnd?: DimensionValue,
38-
+marginHorizontal?: DimensionValue,
39-
+marginLeft?: DimensionValue,
40-
+marginRight?: DimensionValue,
41-
+marginStart?: DimensionValue,
42-
+marginTop?: DimensionValue,
43-
+marginVertical?: DimensionValue,
44-
+padding?: DimensionValue,
45-
+paddingBottom?: DimensionValue,
46-
+paddingEnd?: DimensionValue,
47-
+paddingHorizontal?: DimensionValue,
48-
+paddingLeft?: DimensionValue,
49-
+paddingRight?: DimensionValue,
50-
+paddingStart?: DimensionValue,
51-
+paddingTop?: DimensionValue,
52-
+paddingVertical?: DimensionValue,
53-
+borderWidth?: number,
54-
+borderBottomWidth?: number,
55-
+borderEndWidth?: number,
56-
+borderLeftWidth?: number,
57-
+borderRightWidth?: number,
58-
+borderStartWidth?: number,
59-
+borderTopWidth?: number,
60-
+position?: 'absolute' | 'relative',
61-
+flexDirection?: 'row' | 'row-reverse' | 'column' | 'column-reverse',
62-
+flexWrap?: 'wrap' | 'nowrap',
63-
+justifyContent?:
21+
export type LayoutStyle = $ReadOnly<{|
22+
display?: 'none' | 'flex',
23+
width?: DimensionValue,
24+
height?: DimensionValue,
25+
bottom?: DimensionValue,
26+
end?: DimensionValue,
27+
left?: DimensionValue,
28+
right?: DimensionValue,
29+
start?: DimensionValue,
30+
top?: DimensionValue,
31+
minWidth?: DimensionValue,
32+
maxWidth?: DimensionValue,
33+
minHeight?: DimensionValue,
34+
maxHeight?: DimensionValue,
35+
margin?: DimensionValue,
36+
marginBottom?: DimensionValue,
37+
marginEnd?: DimensionValue,
38+
marginHorizontal?: DimensionValue,
39+
marginLeft?: DimensionValue,
40+
marginRight?: DimensionValue,
41+
marginStart?: DimensionValue,
42+
marginTop?: DimensionValue,
43+
marginVertical?: DimensionValue,
44+
padding?: DimensionValue,
45+
paddingBottom?: DimensionValue,
46+
paddingEnd?: DimensionValue,
47+
paddingHorizontal?: DimensionValue,
48+
paddingLeft?: DimensionValue,
49+
paddingRight?: DimensionValue,
50+
paddingStart?: DimensionValue,
51+
paddingTop?: DimensionValue,
52+
paddingVertical?: DimensionValue,
53+
borderWidth?: number,
54+
borderBottomWidth?: number,
55+
borderEndWidth?: number,
56+
borderLeftWidth?: number,
57+
borderRightWidth?: number,
58+
borderStartWidth?: number,
59+
borderTopWidth?: number,
60+
position?: 'absolute' | 'relative',
61+
flexDirection?: 'row' | 'row-reverse' | 'column' | 'column-reverse',
62+
flexWrap?: 'wrap' | 'nowrap',
63+
justifyContent?:
6464
| 'flex-start'
6565
| 'flex-end'
6666
| 'center'
6767
| 'space-between'
6868
| 'space-around'
6969
| 'space-evenly',
70-
+alignItems?: 'flex-start' | 'flex-end' | 'center' | 'stretch' | 'baseline',
71-
+alignSelf?:
70+
alignItems?: 'flex-start' | 'flex-end' | 'center' | 'stretch' | 'baseline',
71+
alignSelf?:
7272
| 'auto'
7373
| 'flex-start'
7474
| 'flex-end'
7575
| 'center'
7676
| 'stretch'
7777
| 'baseline',
78-
+alignContent?:
78+
alignContent?:
7979
| 'flex-start'
8080
| 'flex-end'
8181
| 'center'
8282
| 'stretch'
8383
| 'space-between'
8484
| 'space-around',
85-
+overflow?: 'visible' | 'hidden' | 'scroll',
86-
+flex?: number,
87-
+flexGrow?: number,
88-
+flexShrink?: number,
89-
+flexBasis?: number | string,
90-
+aspectRatio?: number,
91-
+zIndex?: number,
92-
+direction?: 'inherit' | 'ltr' | 'rtl',
93-
};
85+
overflow?: 'visible' | 'hidden' | 'scroll',
86+
flex?: number,
87+
flexGrow?: number,
88+
flexShrink?: number,
89+
flexBasis?: number | string,
90+
aspectRatio?: number,
91+
zIndex?: number,
92+
direction?: 'inherit' | 'ltr' | 'rtl',
93+
|}>;
9494

95-
export type TransformStyle = {
96-
+transform?: $ReadOnlyArray<
97-
| {+perspective: number | AnimatedNode}
98-
| {+rotate: string}
99-
| {+rotateX: string}
100-
| {+rotateY: string}
101-
| {+rotateZ: string}
102-
| {+scale: number | AnimatedNode}
103-
| {+scaleX: number | AnimatedNode}
104-
| {+scaleY: number | AnimatedNode}
105-
| {+translateX: number | AnimatedNode}
106-
| {+translateY: number | AnimatedNode}
107-
| {
95+
export type TransformStyle = $ReadOnly<{|
96+
transform?: $ReadOnlyArray<
97+
| {|+perspective: number | AnimatedNode|}
98+
| {|+rotate: string|}
99+
| {|+rotateX: string|}
100+
| {|+rotateY: string|}
101+
| {|+rotateZ: string|}
102+
| {|+scale: number | AnimatedNode|}
103+
| {|+scaleX: number | AnimatedNode|}
104+
| {|+scaleY: number | AnimatedNode|}
105+
| {|+translateX: number | AnimatedNode|}
106+
| {|+translateY: number | AnimatedNode|}
107+
| {|
108108
+translate: [number | AnimatedNode, number | AnimatedNode] | AnimatedNode,
109-
}
110-
| {+skewX: string}
111-
| {+skewY: string}
109+
|}
110+
| {|+skewX: string|}
111+
| {|+skewY: string|}
112112
// TODO: what is the actual type it expects?
113-
| {+matrix: $ReadOnlyArray<number | AnimatedNode> | AnimatedNode},
113+
| {|
114+
+matrix: $ReadOnlyArray<number | AnimatedNode> | AnimatedNode,
115+
|},
114116
>,
115-
};
117+
|}>;
116118

117-
export type ShadowStyle = {
118-
+shadowColor?: ColorValue,
119-
+shadowOffset?: {
120-
+width?: number,
121-
+height?: number,
122-
},
123-
+shadowOpacity?: number | AnimatedNode,
124-
+shadowRadius?: number,
125-
};
119+
export type ShadowStyle = $ReadOnly<{|
120+
shadowColor?: ColorValue,
121+
shadowOffset?: $ReadOnly<{|
122+
width?: number,
123+
height?: number,
124+
|}>,
125+
shadowOpacity?: number | AnimatedNode,
126+
shadowRadius?: number,
127+
|}>;
126128

127-
export type ViewStyle = {
129+
export type ViewStyle = $ReadOnly<{|
128130
...$Exact<LayoutStyle>,
129131
...$Exact<ShadowStyle>,
130132
...$Exact<TransformStyle>,
131-
+backfaceVisibility?: 'visible' | 'hidden',
132-
+backgroundColor?: ColorValue,
133-
+borderColor?: ColorValue,
134-
+borderBottomColor?: ColorValue,
135-
+borderEndColor?: ColorValue,
136-
+borderLeftColor?: ColorValue,
137-
+borderRightColor?: ColorValue,
138-
+borderStartColor?: ColorValue,
139-
+borderTopColor?: ColorValue,
140-
+borderRadius?: number,
141-
+borderBottomEndRadius?: number,
142-
+borderBottomLeftRadius?: number,
143-
+borderBottomRightRadius?: number,
144-
+borderBottomStartRadius?: number,
145-
+borderTopEndRadius?: number,
146-
+borderTopLeftRadius?: number,
147-
+borderTopRightRadius?: number,
148-
+borderTopStartRadius?: number,
149-
+borderStyle?: 'solid' | 'dotted' | 'dashed',
150-
+borderWidth?: number,
151-
+borderBottomWidth?: number,
152-
+borderEndWidth?: number,
153-
+borderLeftWidth?: number,
154-
+borderRightWidth?: number,
155-
+borderStartWidth?: number,
156-
+borderTopWidth?: number,
157-
+opacity?: number | AnimatedNode,
158-
+elevation?: number,
159-
};
133+
backfaceVisibility?: 'visible' | 'hidden',
134+
backgroundColor?: ColorValue,
135+
borderColor?: ColorValue,
136+
borderBottomColor?: ColorValue,
137+
borderEndColor?: ColorValue,
138+
borderLeftColor?: ColorValue,
139+
borderRightColor?: ColorValue,
140+
borderStartColor?: ColorValue,
141+
borderTopColor?: ColorValue,
142+
borderRadius?: number,
143+
borderBottomEndRadius?: number,
144+
borderBottomLeftRadius?: number,
145+
borderBottomRightRadius?: number,
146+
borderBottomStartRadius?: number,
147+
borderTopEndRadius?: number,
148+
borderTopLeftRadius?: number,
149+
borderTopRightRadius?: number,
150+
borderTopStartRadius?: number,
151+
borderStyle?: 'solid' | 'dotted' | 'dashed',
152+
borderWidth?: number,
153+
borderBottomWidth?: number,
154+
borderEndWidth?: number,
155+
borderLeftWidth?: number,
156+
borderRightWidth?: number,
157+
borderStartWidth?: number,
158+
borderTopWidth?: number,
159+
opacity?: number | AnimatedNode,
160+
elevation?: number,
161+
|}>;
160162

161-
export type TextStyle = {
163+
export type TextStyle = $ReadOnly<{|
162164
...$Exact<ViewStyle>,
163-
+color?: ColorValue,
164-
+fontFamily?: string,
165-
+fontSize?: number,
166-
+fontStyle?: 'normal' | 'italic',
167-
+fontWeight?:
165+
color?: ColorValue,
166+
fontFamily?: string,
167+
fontSize?: number,
168+
fontStyle?: 'normal' | 'italic',
169+
fontWeight?:
168170
| 'normal'
169171
| 'bold'
170172
| '100'
@@ -176,37 +178,40 @@ export type TextStyle = {
176178
| '700'
177179
| '800'
178180
| '900',
179-
+fontVariant?: $ReadOnlyArray<
181+
fontVariant?: $ReadOnlyArray<
180182
| 'small-caps'
181183
| 'oldstyle-nums'
182184
| 'lining-nums'
183185
| 'tabular-nums'
184186
| 'proportional-nums',
185187
>,
186-
+textShadowOffset?: {+width?: number, +height?: number},
187-
+textShadowRadius?: number,
188-
+textShadowColor?: ColorValue,
189-
+letterSpacing?: number,
190-
+lineHeight?: number,
191-
+textAlign?: 'auto' | 'left' | 'right' | 'center' | 'justify',
192-
+textAlignVertical?: 'auto' | 'top' | 'bottom' | 'center',
193-
+includeFontPadding?: boolean,
194-
+textDecorationLine?:
188+
textShadowOffset?: $ReadOnly<{|
189+
width?: number,
190+
height?: number,
191+
|}>,
192+
textShadowRadius?: number,
193+
textShadowColor?: ColorValue,
194+
letterSpacing?: number,
195+
lineHeight?: number,
196+
textAlign?: 'auto' | 'left' | 'right' | 'center' | 'justify',
197+
textAlignVertical?: 'auto' | 'top' | 'bottom' | 'center',
198+
includeFontPadding?: boolean,
199+
textDecorationLine?:
195200
| 'none'
196201
| 'underline'
197202
| 'line-through'
198203
| 'underline line-through',
199-
+textDecorationStyle?: 'solid' | 'double' | 'dotted' | 'dashed',
200-
+textDecorationColor?: ColorValue,
201-
+writingDirection?: 'auto' | 'ltr' | 'rtl',
202-
};
204+
textDecorationStyle?: 'solid' | 'double' | 'dotted' | 'dashed',
205+
textDecorationColor?: ColorValue,
206+
writingDirection?: 'auto' | 'ltr' | 'rtl',
207+
|}>;
203208

204-
export type ImageStyle = {
209+
export type ImageStyle = $ReadOnly<{|
205210
...$Exact<ViewStyle>,
206-
+resizeMode?: 'contain' | 'cover' | 'stretch' | 'center' | 'repeat',
207-
+tintColor?: ColorValue,
208-
+overlayColor?: string,
209-
};
211+
resizeMode?: 'contain' | 'cover' | 'stretch' | 'center' | 'repeat',
212+
tintColor?: ColorValue,
213+
overlayColor?: string,
214+
|}>;
210215

211216
export type Style = {
212217
...$Exact<TextStyle>,

0 commit comments

Comments
 (0)