Skip to content

Commit e6a303e

Browse files
authored
Style: move Transform method into Style for convenience (#509)
I deleted all the style docs as I am working on it & don't want to keep it in sync ftm. Closes #503
1 parent 672fa5d commit e6a303e

8 files changed

Lines changed: 58 additions & 286 deletions

File tree

‎reason-react-native/src/apis/Animated.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,15 @@ let reset = Animation.reset;
270270
271271
module StyleProp = {
272272
// methods to allow use of Animated values with Style props
273-
273+
274274
// these methods should not be used to get the current value
275275
276276
// for angle, Color.t, and size expressed as percentage,
277277
// interpolated values are needed where the outputRange is
278278
// an appropriate array of strings
279279
280280
external float: value('a) => float = "%identity";
281-
external angle: value(calculated) => Transform.angle = "%identity";
281+
external angle: value(calculated) => Style.angle = "%identity";
282282
external size: value('a) => Style.size = "%identity";
283283
external margin: value('a) => Style.margin = "%identity";
284284
external color: value(calculated) => Color.t = "%identity";

‎reason-react-native/src/apis/Animated.re‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,15 @@ let reset = Animation.reset;
263263

264264
module StyleProp = {
265265
// methods to allow use of Animated values with Style props
266-
266+
267267
// these methods should not be used to get the current value
268268

269269
// for angle, Color.t, and size expressed as percentage,
270270
// interpolated values are needed where the outputRange is
271271
// an appropriate array of strings
272272

273273
external float: value('a) => float = "%identity";
274-
external angle: value(calculated) => Transform.angle = "%identity";
274+
external angle: value(calculated) => Style.angle = "%identity";
275275
external size: value('a) => Style.size = "%identity";
276276
external margin: value('a) => Style.margin = "%identity";
277277
external color: value(calculated) => Color.t = "%identity";

‎reason-react-native/src/apis/Style.bs.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,15 @@ function pct(num) {
55
return num.toString() + "%";
66
}
77

8+
function deg(num) {
9+
return num.toString() + "deg";
10+
}
11+
12+
function rad(num) {
13+
return num.toString() + "rad";
14+
}
15+
816
exports.pct = pct;
17+
exports.deg = deg;
18+
exports.rad = rad;
919
/* No side effect */
Lines changed: 2 additions & 246 deletions
Original file line numberDiff line numberDiff line change
@@ -1,251 +1,7 @@
11
---
22
id: apis/Style
33
title: Style
4-
wip: true
4+
officialDoc: https://facebook.github.io/react-native/docs/style
55
---
66

7-
```reason
8-
type size;
9-
10-
external pt: float => size = "%identity";
11-
12-
let pct: float => size;
13-
14-
type margin = size;
15-
16-
[@bs.inline "auto"]
17-
let auto: margin;
18-
19-
type offset;
20-
[@bs.obj] external offset: (~height: float, ~width: float) => offset = "";
21-
22-
type t;
23-
24-
[@bs.obj]
25-
// Layout Props (https://facebook.github.io/react-native/docs/layout-props#props)
26-
// View Style Props https://facebook.github.io/react-native/docs/view-style-props#props
27-
external style:
28-
(
29-
~alignContent: [@bs.string] [
30-
| [@bs.as "flex-start"] `flexStart
31-
| [@bs.as "flex-end"] `flexEnd
32-
| `center
33-
| `stretch
34-
| [@bs.as "space-around"] `spaceAround
35-
| [@bs.as "space-between"] `spaceBetween
36-
]
37-
=?,
38-
~alignItems: [@bs.string] [
39-
| [@bs.as "flex-start"] `flexStart
40-
| [@bs.as "flex-end"] `flexEnd
41-
| `center
42-
| `stretch
43-
| `baseline
44-
]
45-
=?,
46-
~alignSelf: [@bs.string] [
47-
| [@bs.as "flex-start"] `flexStart
48-
| [@bs.as "flex-end"] `flexEnd
49-
| `center
50-
| `stretch
51-
| `baseline
52-
]
53-
=?,
54-
~aspectRatio: float=?,
55-
~backfaceVisibility: [@bs.string] [ | `visible | `hidden]=?,
56-
~backgroundColor: Color.t=?,
57-
~borderBottomColor: Color.t=?,
58-
~borderBottomEndRadius: float=?,
59-
~borderBottomLeftRadius: float=?,
60-
~borderBottomRightRadius: float=?,
61-
~borderBottomStartRadius: float=?,
62-
~borderBottomWidth: float=?,
63-
~borderColor: Color.t=?,
64-
~borderEndColor: Color.t=?,
65-
~borderEndWidth: float=?,
66-
~borderLeftColor: Color.t=?,
67-
~borderLeftWidth: float=?,
68-
~borderRadius: float=?,
69-
~borderRightColor: Color.t=?,
70-
~borderRightWidth: float=?,
71-
~borderStartColor: Color.t=?,
72-
~borderStartWidth: float=?,
73-
~borderStyle: [@bs.string] [ | `solid | `dotted | `dashed]=?,
74-
~borderTopColor: Color.t=?,
75-
~borderTopEndRadius: float=?,
76-
~borderTopLeftRadius: float=?,
77-
~borderTopRightRadius: float=?,
78-
~borderTopStartRadius: float=?,
79-
~borderTopWidth: float=?,
80-
~borderWidth: float=?,
81-
~bottom: size=?,
82-
~direction: [@bs.string] [ | [@bs.as "inherit"] `inherit_ | `ltr | `ltr]=?,
83-
~display: [@bs.string] [ | `none | `flex]=?,
84-
~elevation: float=?,
85-
~_end: float=?,
86-
~flex: float=?,
87-
~flexBasis: size=?,
88-
~flexDirection: [@bs.string] [
89-
| `row
90-
| [@bs.as "row-reverse"] `rowReverse
91-
| `column
92-
| [@bs.as "column-reverse"] `columnReverse
93-
]
94-
=?,
95-
~flexGrow: float=?,
96-
~flexShrink: float=?,
97-
~flexWrap: [@bs.string] [ | `wrap | `nowrap]=?,
98-
~height: size=?,
99-
~justifyContent: [@bs.string] [
100-
| [@bs.as "flex-start"] `flexStart
101-
| [@bs.as "flex-end"] `flexEnd
102-
| `center
103-
| [@bs.as "space-around"] `spaceAround
104-
| [@bs.as "space-between"] `spaceBetween
105-
| [@bs.as "space-evenly"] `spaceEvenly
106-
]
107-
=?,
108-
~left: size=?,
109-
~margin: size=?,
110-
~marginBottom: size=?,
111-
~marginEnd: size=?,
112-
~marginHorizontal: size=?,
113-
~marginLeft: size=?,
114-
~marginRight: size=?,
115-
~marginStart: size=?,
116-
~marginTop: size=?,
117-
~marginVertical: size=?,
118-
~maxHeight: size=?,
119-
~maxWidth: size=?,
120-
~minHeight: size=?,
121-
~minWidth: size=?,
122-
~opacity: float=?,
123-
~overflow: [@bs.string] [ | `visible | `hidden | `scroll]=?,
124-
~padding: size=?,
125-
~paddingBottom: size=?,
126-
~paddingEnd: size=?,
127-
~paddingHorizontal: size=?,
128-
~paddingLeft: size=?,
129-
~paddingRight: size=?,
130-
~paddingStart: size=?,
131-
~paddingTop: size=?,
132-
~paddingVertical: size=?,
133-
~position: [@bs.string] [ | `absolute | `relative]=?,
134-
~right: size=?,
135-
~start: size=?,
136-
~top: size=?,
137-
~width: size=?,
138-
~zIndex: int=?,
139-
// Shadow Props (https://facebook.github.io/react-native/docs/shadow-props)
140-
~shadowColor: Color.t=?,
141-
~shadowOffset: offset=?,
142-
~shadowOpacity: float=?,
143-
~shadowRadius: float=?,
144-
// Transform Props (https://facebook.github.io/react-native/docs/transforms#props)
145-
~transform: array(Transform.t)=?, // all other transform props are deprecated
146-
// Text Style Props (https://facebook.github.io/react-native/docs/text-style-props)
147-
~color: Color.t=?,
148-
~fontFamily: string=?,
149-
~fontSize: float=?,
150-
~fontStyle: [@bs.string] [ | `normal | `italic]=?,
151-
~fontVariant: array(FontVariant.t)=?,
152-
~fontWeight: [@bs.string] [
153-
| `normal
154-
| `bold
155-
| [@bs.as "100"] `_100
156-
| [@bs.as "200"] `_200
157-
| [@bs.as "300"] `_300
158-
| [@bs.as "400"] `_400
159-
| [@bs.as "500"] `_500
160-
| [@bs.as "600"] `_600
161-
| [@bs.as "700"] `_700
162-
| [@bs.as "800"] `_800
163-
| [@bs.as "900"] `_900
164-
]
165-
=?,
166-
~includeFontPadding: bool=?,
167-
~letterSpacing: float=?,
168-
~lineHeight: float=?,
169-
~textAlign: [@bs.string] [ | `auto | `left | `right | `center | `justify]=?,
170-
~textAlignVertical: [@bs.string] [ | `auto | `top | `bottom | `center]=?,
171-
~textDecorationColor: Color.t=?,
172-
~textDecorationLine: [@bs.string] [
173-
| `none
174-
| `underline
175-
| [@bs.as "line-through"] `lineThrough
176-
| [@bs.as "underline line-through"]
177-
`underlineLineThrough
178-
]
179-
=?,
180-
~textDecorationStyle: [@bs.string] [
181-
| `solid
182-
| `double
183-
| `dotted
184-
| `dashed
185-
]
186-
=?,
187-
~textShadowColor: Color.t=?,
188-
~textShadowOffset: offset=?,
189-
~textShadowRadius: float=?,
190-
~textTransform: [@bs.string] [
191-
| `none
192-
| `uppercase
193-
| `lowercase
194-
| `capitalize
195-
]
196-
=?,
197-
~writingDirection: [@bs.string] [ | `auto | `ltr | `ltr]=?,
198-
// Image Style Props (https://facebook.github.io/react-native/docs/image-style-props)
199-
~resizeMode: [@bs.string] [
200-
| `cover
201-
| `contain
202-
| `stretch
203-
| `repeat
204-
| `center
205-
]
206-
=?,
207-
~overlayColor: Color.t=?,
208-
~tintColor: Color.t=?,
209-
unit
210-
) =>
211-
t =
212-
"";
213-
214-
/*
215-
<View style=array([|
216-
styles##thing,
217-
styles##whatever,
218-
|])>
219-
*/
220-
external array: array(t) => t = "%identity";
221-
222-
/*
223-
<View style=arrayOption([|
224-
Some(styles##thing),
225-
Some(styles##whatever),
226-
optionalStyle,
227-
cond ? Some({something:"dynamic"}) : None
228-
|])>
229-
*/
230-
external arrayOption: array(option(t)) => t = "%identity";
231-
232-
/* list works too since RN accept recursive array of styles (list are just recursive arrays)*/
233-
/*
234-
<View style=list([
235-
styles##thing,
236-
styles##whatever,
237-
])>
238-
*/
239-
external list: list(t) => t = "%identity";
240-
241-
/*
242-
<View style=listOption([
243-
Some(styles##thing),
244-
Some(styles##whatever),
245-
optionalStyle,
246-
cond ? Some({something:"dynamic"}) : None
247-
])>
248-
*/
249-
external listOption: list(option(t)) => t = "%identity";
250-
251-
```
7+
@todo

‎reason-react-native/src/apis/Style.re‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
type t;
2+
13
type size = string;
24

35
external pt: float => size = "%identity";
@@ -12,7 +14,24 @@ let auto = "auto";
1214
type offset;
1315
[@bs.obj] external offset: (~height: float, ~width: float) => offset = "";
1416

15-
type t;
17+
type angle;
18+
let deg: float => angle = num => (num->Js.Float.toString ++ "deg")->Obj.magic;
19+
let rad: float => angle = num => (num->Js.Float.toString ++ "rad")->Obj.magic;
20+
21+
type transform;
22+
[@bs.obj] external perspective: (~perspective: float) => transform = "";
23+
[@bs.obj] external rotate: (~rotate: angle) => transform = "";
24+
[@bs.obj] external rotateX: (~rotateX: angle) => transform = "";
25+
[@bs.obj] external rotateY: (~rotateY: angle) => transform = "";
26+
[@bs.obj] external rotateZ: (~rotateZ: angle) => transform = "";
27+
[@bs.obj] external scale: (~scale: float) => transform = "";
28+
[@bs.obj] external scaleX: (~scaleX: float) => transform = "";
29+
[@bs.obj] external scaleY: (~scaleY: float) => transform = "";
30+
[@bs.obj] external translateX: (~translateX: float) => transform = "";
31+
[@bs.obj] external translateY: (~translateY: float) => transform = "";
32+
[@bs.obj] external skewX: (~skewX: angle) => transform = "";
33+
[@bs.obj] external skewY: (~skewY: angle) => transform = "";
34+
// @todo matrix
1635

1736
[@bs.obj]
1837
// Layout Props (https://facebook.github.io/react-native/docs/layout-props#props)
@@ -135,7 +154,7 @@ external style:
135154
~shadowOpacity: float=?,
136155
~shadowRadius: float=?,
137156
// Transform Props (https://facebook.github.io/react-native/docs/transforms#props)
138-
~transform: array(Transform.t)=?, // all other transform props are deprecated
157+
~transform: array(transform)=?, // all other transform props are deprecated
139158
// Text Style Props (https://facebook.github.io/react-native/docs/text-style-props)
140159
~color: Color.t=?,
141160
~fontFamily: string=?,

‎reason-react-native/src/apis/Style.rei‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
type t;
2+
13
type size;
24

35
external pt: float => size = "%identity";
@@ -12,7 +14,24 @@ let auto: margin;
1214
type offset;
1315
[@bs.obj] external offset: (~height: float, ~width: float) => offset = "";
1416

15-
type t;
17+
type angle;
18+
let deg: float => angle;
19+
let rad: float => angle;
20+
21+
type transform;
22+
[@bs.obj] external perspective: (~perspective: float) => transform = "";
23+
[@bs.obj] external rotate: (~rotate: angle) => transform = "";
24+
[@bs.obj] external rotateX: (~rotateX: angle) => transform = "";
25+
[@bs.obj] external rotateY: (~rotateY: angle) => transform = "";
26+
[@bs.obj] external rotateZ: (~rotateZ: angle) => transform = "";
27+
[@bs.obj] external scale: (~scale: float) => transform = "";
28+
[@bs.obj] external scaleX: (~scaleX: float) => transform = "";
29+
[@bs.obj] external scaleY: (~scaleY: float) => transform = "";
30+
[@bs.obj] external translateX: (~translateX: float) => transform = "";
31+
[@bs.obj] external translateY: (~translateY: float) => transform = "";
32+
[@bs.obj] external skewX: (~skewX: angle) => transform = "";
33+
[@bs.obj] external skewY: (~skewY: angle) => transform = "";
34+
// @todo matrix
1635

1736
[@bs.obj]
1837
// Layout Props (https://facebook.github.io/react-native/docs/layout-props#props)
@@ -135,7 +154,7 @@ external style:
135154
~shadowOpacity: float=?,
136155
~shadowRadius: float=?,
137156
// Transform Props (https://facebook.github.io/react-native/docs/transforms#props)
138-
~transform: array(Transform.t)=?, // all other transform props are deprecated
157+
~transform: array(transform)=?, // all other transform props are deprecated
139158
// Text Style Props (https://facebook.github.io/react-native/docs/text-style-props)
140159
~color: Color.t=?,
141160
~fontFamily: string=?,

0 commit comments

Comments
 (0)