Skip to content

Commit d646004

Browse files
authored
Rename makeConfig -> config, zero-cost bindings for Animation.start, etc. (#391)
1 parent 9394860 commit d646004

3 files changed

Lines changed: 35 additions & 77 deletions

File tree

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

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
'use strict';
22

3-
var Js_undefined = require("bs-platform/lib/js/js_undefined.js");
3+
var Caml_option = require("bs-platform/lib/js/caml_option.js");
44
var ReactNative = require("react-native");
55

6-
function start(t, callback, param) {
7-
t.start(Js_undefined.fromOption(callback));
8-
return /* () */0;
9-
}
10-
11-
var Animation = /* module */[/* start */start];
6+
var Animation = /* module */[];
127

138
function ValueAnimations(Val) {
149
var Decay = /* module */[];
@@ -29,64 +24,26 @@ function interpolate(prim, prim$1) {
2924

3025
var ValueOperations = /* module */[/* interpolate */interpolate];
3126

32-
function resetAnimation(value, callback, param) {
33-
value.resetAnimation(Js_undefined.fromOption(callback));
34-
return /* () */0;
35-
}
36-
37-
function stopAnimation(value, callback, param) {
38-
value.stopAnimation(Js_undefined.fromOption(callback));
39-
return /* () */0;
40-
}
41-
4227
var Decay = /* module */[];
4328

4429
var Spring = /* module */[];
4530

4631
var Timing = /* module */[];
4732

4833
var Value = /* module */[
49-
/* resetAnimation */resetAnimation,
50-
/* stopAnimation */stopAnimation,
5134
/* Decay */Decay,
5235
/* Spring */Spring,
5336
/* Timing */Timing,
5437
/* interpolate */interpolate
5538
];
5639

57-
function create(x, y) {
58-
return new (ReactNative.Animated.ValueXY)({
59-
x: x,
60-
y: y
61-
});
62-
}
63-
64-
function setValue(t, x, y) {
65-
t.setValue({
66-
x: x,
67-
y: y
68-
});
69-
return /* () */0;
70-
}
71-
72-
function setOffset(t, x, y) {
73-
t.setOffset({
74-
x: x,
75-
y: y
76-
});
77-
return /* () */0;
78-
}
79-
8040
var Decay$1 = /* module */[];
8141

8242
var Spring$1 = /* module */[];
8343

8444
var Timing$1 = /* module */[];
8545

8646
var ValueXY = /* module */[
87-
/* create */create,
88-
/* setValue */setValue,
89-
/* setOffset */setOffset,
9047
/* Decay */Decay$1,
9148
/* Spring */Spring$1,
9249
/* Timing */Timing$1
@@ -111,6 +68,11 @@ function decay(prim, prim$1) {
11168
return ReactNative.Animated.decay(prim, prim$1);
11269
}
11370

71+
function start(prim, prim$1, prim$2) {
72+
prim.start(prim$1 !== undefined ? Caml_option.valFromOption(prim$1) : undefined);
73+
return /* () */0;
74+
}
75+
11476
function stop(prim) {
11577
prim.stop();
11678
return /* () */0;

‎bs-react-native-next/src/apis/Animated.md‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module ValueAnimations = (Val: Value) => {
3434
type config;
3535
3636
[@bs.obj]
37-
external makeConfig:
37+
external config:
3838
(
3939
~velocity: Val.rawJsType,
4040
~deceleration: float=?,
@@ -48,7 +48,7 @@ module ValueAnimations = (Val: Value) => {
4848
"";
4949
5050
[@bs.module "react-native"] [@bs.scope "Animated"]
51-
external decay: (~value: Val.t, ~config: config) => Animation.t = "";
51+
external decay: (Val.t, config) => Animation.t = "";
5252
};
5353
5454
module Spring = {
@@ -59,7 +59,7 @@ module ValueAnimations = (Val: Value) => {
5959
type config;
6060
6161
[@bs.obj]
62-
external makeConfig:
62+
external config:
6363
(
6464
~toValue: toValue,
6565
~restDisplacementThreshold: float=?,
@@ -83,7 +83,7 @@ module ValueAnimations = (Val: Value) => {
8383
"";
8484
8585
[@bs.module "react-native"] [@bs.scope "Animated"]
86-
external spring: (~value: Val.t, ~config: config) => Animation.t = "";
86+
external spring: (Val.t, config) => Animation.t = "";
8787
};
8888
8989
module Timing = {
@@ -95,7 +95,7 @@ module ValueAnimations = (Val: Value) => {
9595
type config;
9696
9797
[@bs.obj]
98-
external makeConfig:
98+
external config:
9999
(
100100
~toValue: toValue,
101101
~easing: Easing.t=?,
@@ -111,7 +111,7 @@ module ValueAnimations = (Val: Value) => {
111111
"";
112112
113113
[@bs.module "react-native"] [@bs.scope "Animated"]
114-
external timing: (~value: Val.t, ~config: config) => Animation.t = "";
114+
external timing: (Val.t, config) => Animation.t = "";
115115
};
116116
};
117117
@@ -123,7 +123,7 @@ module Interpolation = {
123123
124124
type config;
125125
[@bs.obj]
126-
external makeConfig:
126+
external config:
127127
(
128128
~inputRange: array(float),
129129
~outputRange: outputRange,
@@ -184,16 +184,11 @@ module Value = {
184184
185185
module ValueXY = {
186186
type t = valueXY;
187-
188187
type jsValue = {
189188
.
190189
"x": float,
191190
"y": float,
192191
};
193-
194-
[@bs.new] [@bs.scope "Animated"] [@bs.module "react-native"]
195-
external create: jsValue => t = "ValueXY";
196-
197192
type callback = jsValue => unit;
198193
type translateTransform = {
199194
.
@@ -205,6 +200,8 @@ module ValueXY = {
205200
"left": Value.t,
206201
"top": Value.t,
207202
};
203+
[@bs.new] [@bs.scope "Animated"] [@bs.module "react-native"]
204+
external create: jsValue => t = "ValueXY";
208205
209206
[@bs.send] external setValue: (t, jsValue) => unit = "";
210207
[@bs.send] external setOffset: (t, jsValue) => unit = "";
@@ -217,7 +214,6 @@ module ValueXY = {
217214
[@bs.send]
218215
external stopAnimation: (t, ~callback: callback=?, unit) => unit =
219216
"stopAnimation";
220-
221217
[@bs.send] external addListener: (t, callback) => string = "addListener";
222218
[@bs.send] external removeListener: (t, string) => unit = "removeListener";
223219
[@bs.send] external removeAllListeners: t => unit = "removeAllListeners";
@@ -274,4 +270,5 @@ let start = Animation.start;
274270
let stop = Animation.stop;
275271
276272
let reset = Animation.reset;
277-
```
273+
274+
```

‎bs-react-native-next/src/apis/Animated.re‎

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ module Animation = {
33
type endResult = {. "finished": bool};
44
type endCallback = endResult => unit;
55
[@bs.send]
6-
external _start: (t, Js.undefined(endCallback)) => unit = "start";
7-
let start = (t, ~callback=?, ()) =>
8-
_start(t, Js.Undefined.fromOption(callback));
6+
external start: (t, ~endCallback: endCallback=?, unit) => unit = "start";
7+
98
[@bs.send] external stop: t => unit = "";
109
[@bs.send] external reset: t => unit = "";
1110
};
@@ -117,7 +116,7 @@ module Interpolation = {
117116

118117
type config;
119118
[@bs.obj]
120-
external makeConfig:
119+
external config:
121120
(
122121
~inputRange: array(float),
123122
~outputRange: outputRange,
@@ -160,16 +159,15 @@ module Value = {
160159
[@bs.send] external addListener: (t, callback) => string = "addListener";
161160
[@bs.send] external removeListener: (t, string) => unit = "removeListener";
162161
[@bs.send] external removeAllListeners: t => unit = "removeAllListeners";
162+
163163
[@bs.send]
164-
external _resetAnimation: (t, Js.Undefined.t(callback)) => unit =
164+
external resetAnimation: (t, ~callback: callback=?, unit) => unit =
165165
"resetAnimation";
166+
166167
[@bs.send]
167-
external _stopAnimation: (t, Js.Undefined.t(callback)) => unit =
168+
external stopAnimation: (t, ~callback: callback=?, unit) => unit =
168169
"stopAnimation";
169-
let resetAnimation = (value, ~callback=?, ()) =>
170-
_resetAnimation(value, Js.Undefined.fromOption(callback));
171-
let stopAnimation = (value, ~callback=?, ()) =>
172-
_stopAnimation(value, Js.Undefined.fromOption(callback));
170+
173171
include ValueAnimations({
174172
type t = value(regular);
175173
type rawJsType = float;
@@ -196,18 +194,19 @@ module ValueXY = {
196194
"top": Value.t,
197195
};
198196
[@bs.new] [@bs.scope "Animated"] [@bs.module "react-native"]
199-
external _create: jsValue => t = "ValueXY";
200-
let create = (~x, ~y) => _create({"x": x, "y": y});
201-
[@bs.send] external _setValue: (t, jsValue) => unit = "setValue";
202-
let setValue = (t, ~x, ~y) => _setValue(t, {"x": x, "y": y});
203-
[@bs.send] external _setOffset: (t, jsValue) => unit = "setOffset";
204-
let setOffset = (t, ~x, ~y) => _setOffset(t, {"x": x, "y": y});
197+
external create: jsValue => t = "ValueXY";
198+
199+
[@bs.send] external setValue: (t, jsValue) => unit = "";
200+
[@bs.send] external setOffset: (t, jsValue) => unit = "";
205201
[@bs.send] external flattenOffset: t => unit = "flattenOffset";
206202
[@bs.send] external extractOffset: t => unit = "extractOffset";
207203
[@bs.send]
208-
external resetAnimation: (t, option(callback)) => unit = "resetAnimation";
204+
external resetAnimation: (t, ~callback: callback=?, unit) => unit =
205+
"resetAnimation";
206+
209207
[@bs.send]
210-
external stopAnimation: (t, option(callback)) => unit = "stopAnimation";
208+
external stopAnimation: (t, ~callback: callback=?, unit) => unit =
209+
"stopAnimation";
211210
[@bs.send] external addListener: (t, callback) => string = "addListener";
212211
[@bs.send] external removeListener: (t, string) => unit = "removeListener";
213212
[@bs.send] external removeAllListeners: t => unit = "removeAllListeners";

0 commit comments

Comments
 (0)