Skip to content

Commit 52a739f

Browse files
authored
Functorize Animated Value and ValueXY (#490)
1 parent f715ce7 commit 52a739f

3 files changed

Lines changed: 78 additions & 72 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ function interpolate(prim, prim$1) {
2828

2929
var ValueOperations = /* module */[/* interpolate */interpolate];
3030

31+
function ValueMethods(Val) {
32+
var Decay = /* module */[];
33+
var Spring = /* module */[];
34+
var Timing = /* module */[];
35+
return /* module */[
36+
/* Decay */Decay,
37+
/* Spring */Spring,
38+
/* Timing */Timing
39+
];
40+
}
41+
3142
var Decay = /* module */[];
3243

3344
var Spring = /* module */[];
@@ -104,6 +115,7 @@ exports.Animation = Animation;
104115
exports.ValueAnimations = ValueAnimations;
105116
exports.Interpolation = Interpolation;
106117
exports.ValueOperations = ValueOperations;
118+
exports.ValueMethods = ValueMethods;
107119
exports.Value = Value;
108120
exports.ValueXY = ValueXY;
109121
exports.timing = timing;

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

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module Animation = {
1818
1919
module type Value = {
2020
type t;
21+
type jsValue;
2122
type rawJsType;
2223
};
2324
@@ -27,8 +28,6 @@ type regular;
2728
2829
type value('a);
2930
30-
type valueXY;
31-
3231
module ValueAnimations = (Val: Value) => {
3332
module Decay = {
3433
type config;
@@ -155,14 +154,15 @@ module ValueOperations = {
155154
let interpolate = Interpolation.interpolate;
156155
};
157156
158-
module Value = {
159-
type t = value(regular);
160-
type jsValue = {. "value": float};
157+
module ValueMethods = (Val: Value) => {
158+
type t = Val.t;
159+
type jsValue = Val.jsValue;
160+
type rawJsType = Val.rawJsType;
161+
161162
type callback = jsValue => unit;
162-
[@bs.new] [@bs.scope "Animated"] [@bs.module "react-native"]
163-
external create: float => t = "Value";
164-
[@bs.send] external setValue: (t, float) => unit = "";
165-
[@bs.send] external setOffset: (t, float) => unit = "";
163+
164+
[@bs.send] external setValue: (t, rawJsType) => unit = "";
165+
[@bs.send] external setOffset: (t, rawJsType) => unit = "";
166166
[@bs.send] external flattenOffset: t => unit = "";
167167
[@bs.send] external extractOffset: t => unit = "";
168168
[@bs.send] external addListener: (t, callback) => string = "";
@@ -175,21 +175,37 @@ module Value = {
175175
[@bs.send]
176176
external stopAnimation: (t, ~callback: callback=?, unit) => unit = "";
177177
178-
include ValueAnimations({
178+
include ValueAnimations(Val);
179+
};
180+
181+
module Value = {
182+
include ValueMethods({
179183
type t = value(regular);
184+
type jsValue = {. "value": float};
180185
type rawJsType = float;
181186
});
187+
188+
[@bs.new] [@bs.scope "Animated"] [@bs.module "react-native"]
189+
external create: float => t = "Value";
190+
182191
include ValueOperations;
183192
};
184193
185194
module ValueXY = {
186-
type t = valueXY;
187-
type jsValue = {
188-
.
189-
"x": float,
190-
"y": float,
191-
};
192-
type callback = jsValue => unit;
195+
include ValueMethods({
196+
type t = {
197+
.
198+
"x": Value.t,
199+
"y": Value.t,
200+
};
201+
type jsValue = {
202+
.
203+
"x": float,
204+
"y": float,
205+
};
206+
type rawJsType = jsValue;
207+
});
208+
193209
type translateTransform = {
194210
.
195211
"translateX": Value.t,
@@ -202,27 +218,8 @@ module ValueXY = {
202218
};
203219
[@bs.new] [@bs.scope "Animated"] [@bs.module "react-native"]
204220
external create: jsValue => t = "ValueXY";
205-
206-
[@bs.send] external setValue: (t, jsValue) => unit = "";
207-
[@bs.send] external setOffset: (t, jsValue) => unit = "";
208-
[@bs.send] external flattenOffset: t => unit = "";
209-
[@bs.send] external extractOffset: t => unit = "";
210-
[@bs.send]
211-
external resetAnimation: (t, ~callback: callback=?, unit) => unit = "";
212-
213-
[@bs.send]
214-
external stopAnimation: (t, ~callback: callback=?, unit) => unit = "";
215-
[@bs.send] external addListener: (t, callback) => string = "";
216-
[@bs.send] external removeListener: (t, string) => unit = "";
217-
[@bs.send] external removeAllListeners: t => unit = "";
218221
[@bs.send] external getLayout: t => layout = "";
219222
[@bs.send] external getTranslateTransform: t => translateTransform = "";
220-
[@bs.get] external getX: t => Value.t = "x";
221-
[@bs.get] external getY: t => Value.t = "y";
222-
include ValueAnimations({
223-
type t = valueXY;
224-
type rawJsType = jsValue;
225-
});
226223
};
227224
228225
[@bs.module "react-native"] [@bs.scope "Animated"]

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

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Animation = {
1111

1212
module type Value = {
1313
type t;
14+
type jsValue;
1415
type rawJsType;
1516
};
1617

@@ -20,8 +21,6 @@ type regular;
2021

2122
type value('a);
2223

23-
type valueXY;
24-
2524
module ValueAnimations = (Val: Value) => {
2625
module Decay = {
2726
type config;
@@ -148,14 +147,15 @@ module ValueOperations = {
148147
let interpolate = Interpolation.interpolate;
149148
};
150149

151-
module Value = {
152-
type t = value(regular);
153-
type jsValue = {. "value": float};
150+
module ValueMethods = (Val: Value) => {
151+
type t = Val.t;
152+
type jsValue = Val.jsValue;
153+
type rawJsType = Val.rawJsType;
154+
154155
type callback = jsValue => unit;
155-
[@bs.new] [@bs.scope "Animated"] [@bs.module "react-native"]
156-
external create: float => t = "Value";
157-
[@bs.send] external setValue: (t, float) => unit = "";
158-
[@bs.send] external setOffset: (t, float) => unit = "";
156+
157+
[@bs.send] external setValue: (t, rawJsType) => unit = "";
158+
[@bs.send] external setOffset: (t, rawJsType) => unit = "";
159159
[@bs.send] external flattenOffset: t => unit = "";
160160
[@bs.send] external extractOffset: t => unit = "";
161161
[@bs.send] external addListener: (t, callback) => string = "";
@@ -168,21 +168,37 @@ module Value = {
168168
[@bs.send]
169169
external stopAnimation: (t, ~callback: callback=?, unit) => unit = "";
170170

171-
include ValueAnimations({
171+
include ValueAnimations(Val);
172+
};
173+
174+
module Value = {
175+
include ValueMethods({
172176
type t = value(regular);
177+
type jsValue = {. "value": float};
173178
type rawJsType = float;
174179
});
180+
181+
[@bs.new] [@bs.scope "Animated"] [@bs.module "react-native"]
182+
external create: float => t = "Value";
183+
175184
include ValueOperations;
176185
};
177186

178187
module ValueXY = {
179-
type t = valueXY;
180-
type jsValue = {
181-
.
182-
"x": float,
183-
"y": float,
184-
};
185-
type callback = jsValue => unit;
188+
include ValueMethods({
189+
type t = {
190+
.
191+
"x": Value.t,
192+
"y": Value.t,
193+
};
194+
type jsValue = {
195+
.
196+
"x": float,
197+
"y": float,
198+
};
199+
type rawJsType = jsValue;
200+
});
201+
186202
type translateTransform = {
187203
.
188204
"translateX": Value.t,
@@ -195,27 +211,8 @@ module ValueXY = {
195211
};
196212
[@bs.new] [@bs.scope "Animated"] [@bs.module "react-native"]
197213
external create: jsValue => t = "ValueXY";
198-
199-
[@bs.send] external setValue: (t, jsValue) => unit = "";
200-
[@bs.send] external setOffset: (t, jsValue) => unit = "";
201-
[@bs.send] external flattenOffset: t => unit = "";
202-
[@bs.send] external extractOffset: t => unit = "";
203-
[@bs.send]
204-
external resetAnimation: (t, ~callback: callback=?, unit) => unit = "";
205-
206-
[@bs.send]
207-
external stopAnimation: (t, ~callback: callback=?, unit) => unit = "";
208-
[@bs.send] external addListener: (t, callback) => string = "";
209-
[@bs.send] external removeListener: (t, string) => unit = "";
210-
[@bs.send] external removeAllListeners: t => unit = "";
211214
[@bs.send] external getLayout: t => layout = "";
212215
[@bs.send] external getTranslateTransform: t => translateTransform = "";
213-
[@bs.get] external getX: t => Value.t = "x";
214-
[@bs.get] external getY: t => Value.t = "y";
215-
include ValueAnimations({
216-
type t = valueXY;
217-
type rawJsType = jsValue;
218-
});
219216
};
220217

221218
[@bs.module "react-native"] [@bs.scope "Animated"]

0 commit comments

Comments
 (0)