Skip to content

Commit bdafc55

Browse files
javachefacebook-github-bot
authored andcommitted
Make animation types exact
Summary: Changelog: [General][Changed] Improved flowtype support for Animated Reviewed By: cpojer Differential Revision: D20002839 fbshipit-source-id: 537ac00b3fe408585d34a0ffac8adc598e01d1b7
1 parent c18fa70 commit bdafc55

9 files changed

+26
-27
lines changed

Libraries/Animated/src/AnimatedEvent.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export type Mapping = {[key: string]: Mapping, ...} | AnimatedValue;
2222
export type EventConfig = {
2323
listener?: ?Function,
2424
useNativeDriver: boolean,
25-
...
2625
};
2726

2827
function attachNativeEvent(
@@ -140,7 +139,7 @@ class AnimatedEvent {
140139

141140
if (config == null) {
142141
console.warn('Animated.event now requires a second argument for options');
143-
config = {};
142+
config = {useNativeDriver: false};
144143
}
145144

146145
if (config.listener) {

Libraries/Animated/src/AnimatedImplementation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const diffClamp = function(
9191

9292
const _combineCallbacks = function(
9393
callback: ?EndCallback,
94-
config: AnimationConfig,
94+
config: {...AnimationConfig, ...},
9595
) {
9696
if (callback && config.onComplete) {
9797
return (...args) => {

Libraries/Animated/src/NativeAnimatedHelper.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,9 @@ function assertNativeAnimatedModule(): void {
277277

278278
let _warnedMissingNativeAnimated = false;
279279

280-
function shouldUseNativeDriver(config: AnimationConfig | EventConfig): boolean {
280+
function shouldUseNativeDriver(
281+
config: {...AnimationConfig, ...} | EventConfig,
282+
): boolean {
281283
if (config.useNativeDriver == null) {
282284
console.warn(
283285
'Animated: `useNativeDriver` was not specified. This is a required ' +

Libraries/Animated/src/animations/Animation.js

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export type AnimationConfig = {
2222
useNativeDriver: boolean,
2323
onComplete?: ?EndCallback,
2424
iterations?: number,
25-
...
2625
};
2726

2827
// Important note: start() and stop() will only be called at most once.

Libraries/Animated/src/animations/DecayAnimation.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const {shouldUseNativeDriver} = require('../NativeAnimatedHelper');
1717
import type AnimatedValue from '../nodes/AnimatedValue';
1818
import type {AnimationConfig, EndCallback} from './Animation';
1919

20-
export type DecayAnimationConfig = AnimationConfig & {
20+
export type DecayAnimationConfig = {
21+
...AnimationConfig,
2122
velocity:
2223
| number
2324
| {
@@ -26,13 +27,12 @@ export type DecayAnimationConfig = AnimationConfig & {
2627
...
2728
},
2829
deceleration?: number,
29-
...
3030
};
3131

32-
export type DecayAnimationConfigSingle = AnimationConfig & {
32+
export type DecayAnimationConfigSingle = {
33+
...AnimationConfig,
3334
velocity: number,
3435
deceleration?: number,
35-
...
3636
};
3737

3838
class DecayAnimation extends Animation {

Libraries/Animated/src/animations/SpringAnimation.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ const {shouldUseNativeDriver} = require('../NativeAnimatedHelper');
2222

2323
import type {AnimationConfig, EndCallback} from './Animation';
2424

25-
export type SpringAnimationConfig = AnimationConfig & {
25+
export type SpringAnimationConfig = {
26+
...AnimationConfig,
2627
toValue:
2728
| number
2829
| AnimatedValue
@@ -51,10 +52,10 @@ export type SpringAnimationConfig = AnimationConfig & {
5152
damping?: number,
5253
mass?: number,
5354
delay?: number,
54-
...
5555
};
5656

57-
export type SpringAnimationConfigSingle = AnimationConfig & {
57+
export type SpringAnimationConfigSingle = {
58+
...AnimationConfig,
5859
toValue: number | AnimatedValue | AnimatedInterpolation,
5960
overshootClamping?: boolean,
6061
restDisplacementThreshold?: number,
@@ -68,7 +69,6 @@ export type SpringAnimationConfigSingle = AnimationConfig & {
6869
damping?: number,
6970
mass?: number,
7071
delay?: number,
71-
...
7272
};
7373

7474
class SpringAnimation extends Animation {

Libraries/Animated/src/animations/TimingAnimation.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const {shouldUseNativeDriver} = require('../NativeAnimatedHelper');
1919

2020
import type {AnimationConfig, EndCallback} from './Animation';
2121

22-
export type TimingAnimationConfig = AnimationConfig & {
22+
export type TimingAnimationConfig = {
23+
...AnimationConfig,
2324
toValue:
2425
| number
2526
| AnimatedValue
@@ -33,15 +34,14 @@ export type TimingAnimationConfig = AnimationConfig & {
3334
easing?: (value: number) => number,
3435
duration?: number,
3536
delay?: number,
36-
...
3737
};
3838

39-
export type TimingAnimationConfigSingle = AnimationConfig & {
39+
export type TimingAnimationConfigSingle = {
40+
...AnimationConfig,
4041
toValue: number | AnimatedValue | AnimatedInterpolation,
4142
easing?: (value: number) => number,
4243
duration?: number,
4344
delay?: number,
44-
...
4545
};
4646

4747
let _easeInOut;

Libraries/Animated/src/nodes/AnimatedInterpolation.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@ const normalizeColor = require('../../../StyleSheet/normalizeColor');
2222
type ExtrapolateType = 'extend' | 'identity' | 'clamp';
2323

2424
export type InterpolationConfigType = {
25-
inputRange: Array<number>,
25+
inputRange: $ReadOnlyArray<number>,
2626
/* $FlowFixMe(>=0.38.0 site=react_native_fb,react_native_oss) - Flow error
2727
* detected during the deployment of v0.38.0. To see the error, remove this
2828
* comment and run flow
2929
*/
30-
outputRange: Array<number> | Array<string>,
30+
outputRange: $ReadOnlyArray<number> | $ReadOnlyArray<string>,
3131
easing?: (input: number) => number,
3232
extrapolate?: ExtrapolateType,
3333
extrapolateLeft?: ExtrapolateType,
3434
extrapolateRight?: ExtrapolateType,
35-
...
3635
};
3736

3837
const linear = t => t;
@@ -258,7 +257,7 @@ function isRgbOrRgba(range) {
258257
return typeof range === 'string' && range.startsWith('rgb');
259258
}
260259

261-
function checkPattern(arr: Array<string>) {
260+
function checkPattern(arr: $ReadOnlyArray<string>) {
262261
const pattern = arr[0].replace(stringShapeRegex, '');
263262
for (let i = 1; i < arr.length; ++i) {
264263
invariant(
@@ -268,7 +267,7 @@ function checkPattern(arr: Array<string>) {
268267
}
269268
}
270269

271-
function findRange(input: number, inputRange: Array<number>) {
270+
function findRange(input: number, inputRange: $ReadOnlyArray<number>) {
272271
let i;
273272
for (i = 1; i < inputRange.length - 1; ++i) {
274273
if (inputRange[i] >= input) {
@@ -278,7 +277,7 @@ function findRange(input: number, inputRange: Array<number>) {
278277
return i - 1;
279278
}
280279

281-
function checkValidInputRange(arr: Array<number>) {
280+
function checkValidInputRange(arr: $ReadOnlyArray<number>) {
282281
invariant(arr.length >= 2, 'inputRange must have at least 2 elements');
283282
for (let i = 1; i < arr.length; ++i) {
284283
invariant(
@@ -294,7 +293,7 @@ function checkValidInputRange(arr: Array<number>) {
294293
}
295294
}
296295

297-
function checkInfiniteRange(name: string, arr: Array<number>) {
296+
function checkInfiniteRange(name: string, arr: $ReadOnlyArray<number>) {
298297
invariant(arr.length >= 2, name + ' must have at least 2 elements');
299298
invariant(
300299
arr.length !== 2 || arr[0] !== -Infinity || arr[1] !== Infinity,

RNTester/js/examples/MaskedView/MaskedViewExample.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ class AnimatedMaskExample extends React.Component<Props> {
3535
Animated.sequence([
3636
Animated.timing(this._maskScaleAnimatedValue, {
3737
toValue: 1.3,
38-
timing: 750,
38+
duration: 750,
3939
useNativeDriver: true,
4040
}),
4141
Animated.timing(this._maskScaleAnimatedValue, {
4242
toValue: 1,
43-
timing: 750,
43+
duration: 750,
4444
useNativeDriver: true,
4545
}),
4646
]),
@@ -49,7 +49,7 @@ class AnimatedMaskExample extends React.Component<Props> {
4949
Animated.loop(
5050
Animated.timing(this._maskRotateAnimatedValue, {
5151
toValue: 360,
52-
timing: 2000,
52+
duration: 2000,
5353
useNativeDriver: true,
5454
}),
5555
).start();

0 commit comments

Comments
 (0)