Skip to content

Commit a089ba8

Browse files
sgnyMoOx
authored andcommitted
Animated: add more precise methods to use values as Style props (#508)
1 parent 322f4e8 commit a089ba8

3 files changed

Lines changed: 41 additions & 6 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ function reset(prim) {
9191
return /* () */0;
9292
}
9393

94+
var StyleProp = /* module */[];
95+
9496
var make = ReactNative.Animated.createAnimatedComponent(ReactNative.Image);
9597

9698
var $$Image = /* module */[
@@ -124,6 +126,7 @@ exports.decay = decay;
124126
exports.start = start;
125127
exports.stop = stop;
126128
exports.reset = reset;
129+
exports.StyleProp = StyleProp;
127130
exports.$$Image = $$Image;
128131
exports.ScrollView = ScrollView;
129132
exports.$$Text = $$Text;

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,25 @@ let stop = Animation.stop;
268268
269269
let reset = Animation.reset;
270270
271-
// Unsafe, unfortunately, but allows us to pass animated values everywhere.
272-
// May be refined later.
273-
external animatedStyle: value('a) => 'b = "%identity";
271+
module StyleProp = {
272+
// methods to allow use of Animated values with Style props
273+
274+
// these methods should not be used to get the current value
275+
276+
// for angle, Color.t, and size expressed as percentage,
277+
// interpolated values are needed where the outputRange is
278+
// an appropriate array of strings
279+
280+
external float: value('a) => float = "%identity";
281+
external angle: value(calculated) => Transform.angle = "%identity";
282+
external size: value('a) => Style.size = "%identity";
283+
external margin: value('a) => Style.margin = "%identity";
284+
external color: value(calculated) => Color.t = "%identity";
285+
286+
// UNSAFE: allows to pass animated values everywhere,
287+
// use of more precise methods above is recommended
288+
external unsafeAny: value('a) => 'b = "%identity";
289+
};
274290
275291
module Image = {
276292
include Image;

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,25 @@ let stop = Animation.stop;
261261

262262
let reset = Animation.reset;
263263

264-
// Unsafe, unfortunately, but allows us to pass animated values everywhere.
265-
// May be refined later.
266-
external animatedStyle: value('a) => 'b = "%identity";
264+
module StyleProp = {
265+
// methods to allow use of Animated values with Style props
266+
267+
// these methods should not be used to get the current value
268+
269+
// for angle, Color.t, and size expressed as percentage,
270+
// interpolated values are needed where the outputRange is
271+
// an appropriate array of strings
272+
273+
external float: value('a) => float = "%identity";
274+
external angle: value(calculated) => Transform.angle = "%identity";
275+
external size: value('a) => Style.size = "%identity";
276+
external margin: value('a) => Style.margin = "%identity";
277+
external color: value(calculated) => Color.t = "%identity";
278+
279+
// UNSAFE: allows to pass animated values everywhere,
280+
// use of more precise methods above is recommended
281+
external unsafeAny: value('a) => 'b = "%identity";
282+
};
267283

268284
module Image = {
269285
include Image;

0 commit comments

Comments
 (0)