Skip to content

Commit 69519b2

Browse files
authored
Style: Add unsafeAddStyle, unsafeStyle & unsafeTransform as escape hatch (#510)
* Add unsafeAddProp (like ReactDOMRe.Style) & unsafeTransform as escape hatch for fancy platforms (and move array/list(Option) at the top - without huge comments) This escape hatch are a necessity when using react-native-web (eg: position: fixed on the web - as you cannot always have 60fps sticky header with interpolation+translateY... Also RNW allows `translateZ`etc...) * Replace with unsafeAddStyle, unsafeStyle & unsafeTransform * Zero cost unsafeAddStyle 🤯
1 parent e6a303e commit 69519b2

File tree

2 files changed

+28
-74
lines changed

2 files changed

+28
-74
lines changed

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

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
type t;
22

3+
external array: array(t) => t = "%identity";
4+
external arrayOption: array(option(t)) => t = "%identity";
5+
/* list works too since RN accept recursive array of styles (ocaml list are recursive arrays in JS)*/
6+
external list: list(t) => t = "%identity";
7+
external listOption: list(option(t)) => t = "%identity";
8+
9+
// Escape hatch, in case something is added into RN but unsupported,
10+
// Useful if you play with fancy platforms
11+
// Use with caution
12+
[@bs.val]
13+
external unsafeAddStyle: ([@bs.as {json|{}|json}] _, t, Js.t('a)) => t =
14+
"Object.assign";
15+
16+
external unsafeStyle: Js.t('a) => t = "%identity";
17+
318
type size = string;
419

520
external pt: float => size = "%identity";
@@ -33,6 +48,8 @@ type transform;
3348
[@bs.obj] external skewY: (~skewY: angle) => transform = "";
3449
// @todo matrix
3550

51+
external unsafeTransform: Js.t('a) => transform = "%identity";
52+
3653
[@bs.obj]
3754
// Layout Props (https://facebook.github.io/react-native/docs/layout-props#props)
3855
// View Style Props https://facebook.github.io/react-native/docs/view-style-props#props
@@ -222,40 +239,3 @@ external style:
222239
) =>
223240
t =
224241
"";
225-
226-
/*
227-
<View style=array([|
228-
styles##thing,
229-
styles##whatever,
230-
|])>
231-
*/
232-
external array: array(t) => t = "%identity";
233-
234-
/*
235-
<View style=arrayOption([|
236-
Some(styles##thing),
237-
Some(styles##whatever),
238-
optionalStyle,
239-
cond ? Some({something:"dynamic"}) : None
240-
|])>
241-
*/
242-
external arrayOption: array(option(t)) => t = "%identity";
243-
244-
/* list works too since RN accept recursive array of styles (list are just recursive arrays)*/
245-
/*
246-
<View style=list([
247-
styles##thing,
248-
styles##whatever,
249-
])>
250-
*/
251-
external list: list(t) => t = "%identity";
252-
253-
/*
254-
<View style=listOption([
255-
Some(styles##thing),
256-
Some(styles##whatever),
257-
optionalStyle,
258-
cond ? Some({something:"dynamic"}) : None
259-
])>
260-
*/
261-
external listOption: list(option(t)) => t = "%identity";

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

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
type t;
22

3+
external array: array(t) => t = "%identity";
4+
external arrayOption: array(option(t)) => t = "%identity";
5+
external list: list(t) => t = "%identity";
6+
external listOption: list(option(t)) => t = "%identity";
7+
[@bs.val]
8+
external unsafeAddStyle: ([@bs.as {json|{}|json}] _, t, Js.t('a)) => t =
9+
"Object.assign";
10+
external unsafeStyle: Js.t('a) => t = "%identity";
11+
312
type size;
413

514
external pt: float => size = "%identity";
@@ -33,6 +42,8 @@ type transform;
3342
[@bs.obj] external skewY: (~skewY: angle) => transform = "";
3443
// @todo matrix
3544

45+
external unsafeTransform: Js.t('a) => transform = "%identity";
46+
3647
[@bs.obj]
3748
// Layout Props (https://facebook.github.io/react-native/docs/layout-props#props)
3849
// View Style Props https://facebook.github.io/react-native/docs/view-style-props#props
@@ -222,40 +233,3 @@ external style:
222233
) =>
223234
t =
224235
"";
225-
226-
/*
227-
<View style=array([|
228-
styles##thing,
229-
styles##whatever,
230-
|])>
231-
*/
232-
external array: array(t) => t = "%identity";
233-
234-
/*
235-
<View style=arrayOption([|
236-
Some(styles##thing),
237-
Some(styles##whatever),
238-
optionalStyle,
239-
cond ? Some({something:"dynamic"}) : None
240-
|])>
241-
*/
242-
external arrayOption: array(option(t)) => t = "%identity";
243-
244-
/* list works too since RN accept recursive array of styles (list are just recursive arrays)*/
245-
/*
246-
<View style=list([
247-
styles##thing,
248-
styles##whatever,
249-
])>
250-
*/
251-
external list: list(t) => t = "%identity";
252-
253-
/*
254-
<View style=listOption([
255-
Some(styles##thing),
256-
Some(styles##whatever),
257-
optionalStyle,
258-
cond ? Some({something:"dynamic"}) : None
259-
])>
260-
*/
261-
external listOption: list(option(t)) => t = "%identity";

0 commit comments

Comments
 (0)