Skip to content

Commit 3b4bde3

Browse files
rubennortemeta-codesync[bot]
authored andcommitted
Make remaining Animated modules Flow strict-local (#57727)
Summary: Pull Request resolved: #57727 Upgrade the remaining Animated modules from `flow` to `flow strict-local`. Public type signatures are preserved exactly, so consumers are unaffected; mechanical violations were fixed accurately, and the genuinely-dynamic internal `any` usages (Animated's value graph operates on values of arbitrary shape) are marked with scoped `$FlowFixMe[unclear-type]` where an accurate type cannot be expressed. Changelog: [Internal] Reviewed By: javache Differential Revision: D113763788
1 parent e16710b commit 3b4bde3

8 files changed

Lines changed: 69 additions & 9 deletions

File tree

packages/react-native/Libraries/Animated/AnimatedEvent.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow
7+
* @flow strict-local
88
* @format
99
*/
1010

@@ -29,6 +29,7 @@ export type EventConfig<T> = {
2929
};
3030

3131
export function attachNativeEventImpl(
32+
// $FlowFixMe[unclear-type]
3233
viewRef: any,
3334
eventName: string,
3435
argMapping: ReadonlyArray<?Mapping>,
@@ -57,6 +58,7 @@ export function attachNativeEventImpl(
5758
};
5859

5960
invariant(
61+
// $FlowFixMe[sketchy-null-mixed]
6062
argMapping[0] && argMapping[0].nativeEvent,
6163
'Native driven events only support animated values contained inside `nativeEvent`.',
6264
);
@@ -91,7 +93,9 @@ export function attachNativeEventImpl(
9193
};
9294
}
9395

96+
// $FlowFixMe[unclear-type]
9497
function validateMapping(argMapping: ReadonlyArray<?Mapping>, args: any) {
98+
// $FlowFixMe[unclear-type]
9599
const validate = (recMapping: ?Mapping, recEvt: any, key: string) => {
96100
if (recMapping instanceof AnimatedValue) {
97101
invariant(
@@ -145,16 +149,19 @@ function validateMapping(argMapping: ReadonlyArray<?Mapping>, args: any) {
145149

146150
export class AnimatedEvent {
147151
_argMapping: ReadonlyArray<?Mapping>;
152+
// $FlowFixMe[unclear-type]
148153
_listeners: Array<Function> = [];
149154
_attachedEvent: ?{detach: () => void, ...};
150155
__isNative: boolean;
151156
__platformConfig: ?PlatformConfig;
152157

158+
// $FlowFixMe[unclear-type]
153159
constructor(argMapping: ReadonlyArray<?Mapping>, config: EventConfig<any>) {
154160
this._argMapping = argMapping;
155161

156162
if (config == null) {
157163
console.warn('Animated.event now requires a second argument for options');
164+
// $FlowFixMe[reassign-const]
158165
config = {useNativeDriver: false};
159166
}
160167

@@ -166,14 +173,17 @@ export class AnimatedEvent {
166173
this.__platformConfig = config.platformConfig;
167174
}
168175

176+
// $FlowFixMe[unclear-type]
169177
__addListener(callback: Function): void {
170178
this._listeners.push(callback);
171179
}
172180

181+
// $FlowFixMe[unclear-type]
173182
__removeListener(callback: Function): void {
174183
this._listeners = this._listeners.filter(listener => listener !== callback);
175184
}
176185

186+
// $FlowFixMe[unclear-type]
177187
__attach(viewRef: any, eventName: string): void {
178188
invariant(
179189
this.__isNative,
@@ -188,6 +198,7 @@ export class AnimatedEvent {
188198
);
189199
}
190200

201+
// $FlowFixMe[unclear-type]
191202
__detach(viewTag: any, eventName: string): void {
192203
invariant(
193204
this.__isNative,
@@ -197,10 +208,12 @@ export class AnimatedEvent {
197208
this._attachedEvent && this._attachedEvent.detach();
198209
}
199210

211+
// $FlowFixMe[unclear-type]
200212
__getHandler(): (...args: any) => void {
201213
if (this.__isNative) {
202214
if (__DEV__) {
203215
let validatedMapping = false;
216+
// $FlowFixMe[unclear-type]
204217
return (...args: any) => {
205218
if (!validatedMapping) {
206219
validateMapping(this._argMapping, args);
@@ -214,6 +227,7 @@ export class AnimatedEvent {
214227
}
215228

216229
let validatedMapping = false;
230+
// $FlowFixMe[unclear-type]
217231
return (...args: any) => {
218232
if (__DEV__ && !validatedMapping) {
219233
validateMapping(this._argMapping, args);
@@ -222,6 +236,7 @@ export class AnimatedEvent {
222236

223237
const traverse = (
224238
recMapping: ?(Mapping | AnimatedValue),
239+
// $FlowFixMe[unclear-type]
225240
recEvt: any,
226241
) => {
227242
if (recMapping instanceof AnimatedValue) {
@@ -250,6 +265,7 @@ export class AnimatedEvent {
250265
};
251266
}
252267

268+
// $FlowFixMe[unclear-type]
253269
_callListeners = (...args: any) => {
254270
this._listeners.forEach(listener => listener(...args));
255271
};

packages/react-native/Libraries/Animated/AnimatedImplementation.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow
7+
* @flow strict-local
88
* @format
99
*/
1010

@@ -127,7 +127,9 @@ const _combineCallbacks = function (
127127

128128
const maybeVectorAnim = function (
129129
value: AnimatedValue | AnimatedValueXY | AnimatedColor,
130+
// $FlowFixMe[unclear-type]
130131
config: Object,
132+
// $FlowFixMe[unclear-type]
131133
anim: (value: AnimatedValue, config: Object) => CompositeAnimation,
132134
): ?CompositeAnimation {
133135
if (value instanceof AnimatedValueXY) {
@@ -184,8 +186,11 @@ const springImpl = function (
184186
configuration: SpringAnimationConfig,
185187
callback?: ?EndCallback,
186188
): void {
189+
// $FlowFixMe[reassign-const]
187190
callback = _combineCallbacks(callback, configuration);
191+
// $FlowFixMe[unclear-type]
188192
const singleValue: any = animatedValue;
193+
// $FlowFixMe[unclear-type]
189194
const singleConfig: any = configuration;
190195
singleValue.stopTracking();
191196
if (configuration.toValue instanceof AnimatedNode) {
@@ -241,8 +246,11 @@ const timingImpl = function (
241246
configuration: TimingAnimationConfig,
242247
callback?: ?EndCallback,
243248
): void {
249+
// $FlowFixMe[reassign-const]
244250
callback = _combineCallbacks(callback, configuration);
251+
// $FlowFixMe[unclear-type]
245252
const singleValue: any = animatedValue;
253+
// $FlowFixMe[unclear-type]
246254
const singleConfig: any = configuration;
247255
singleValue.stopTracking();
248256
if (configuration.toValue instanceof AnimatedNode) {
@@ -299,8 +307,11 @@ const decayImpl = function (
299307
configuration: DecayAnimationConfig,
300308
callback?: ?EndCallback,
301309
): void {
310+
// $FlowFixMe[reassign-const]
302311
callback = _combineCallbacks(callback, configuration);
312+
// $FlowFixMe[unclear-type]
303313
const singleValue: any = animatedValue;
314+
// $FlowFixMe[unclear-type]
304315
const singleConfig: any = configuration;
305316
singleValue.stopTracking();
306317
singleValue.animate(new DecayAnimation(singleConfig), callback);
@@ -551,8 +562,11 @@ const loopImpl = function (
551562
};
552563

553564
function forkEventImpl(
565+
// $FlowFixMe[unclear-type]
554566
event: ?AnimatedEvent | ?Function,
567+
// $FlowFixMe[unclear-type]
555568
listener: Function,
569+
// $FlowFixMe[unclear-type]
556570
): AnimatedEvent | Function {
557571
if (!event) {
558572
return listener;
@@ -568,7 +582,9 @@ function forkEventImpl(
568582
}
569583

570584
function unforkEventImpl(
585+
// $FlowFixMe[unclear-type]
571586
event: ?AnimatedEvent | ?Function,
587+
// $FlowFixMe[unclear-type]
572588
listener: Function,
573589
): void {
574590
if (event && event instanceof AnimatedEvent) {
@@ -583,6 +599,7 @@ function unforkEventImpl(
583599
const eventImpl: <T>(
584600
argMapping: ReadonlyArray<?Mapping>,
585601
config: EventConfig<T>,
602+
// $FlowFixMe[unclear-type]
586603
) => (...args: Array<any>) => void = function (argMapping, config): any {
587604
const animatedEvent = new AnimatedEvent(argMapping, config);
588605
if (animatedEvent.__isNative) {

packages/react-native/Libraries/Animated/AnimatedMock.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow
7+
* @flow strict-local
88
* @format
99
*/
1010

@@ -94,6 +94,7 @@ const spring = function (
9494
value: AnimatedValue | AnimatedValueXY | AnimatedColor,
9595
config: SpringAnimationConfig,
9696
): CompositeAnimation {
97+
// $FlowFixMe[unclear-type]
9798
const anyValue: any = value;
9899
return {
99100
...emptyAnimation,
@@ -108,6 +109,7 @@ const timing = function (
108109
value: AnimatedValue | AnimatedValueXY | AnimatedColor,
109110
config: TimingAnimationConfig,
110111
): CompositeAnimation {
112+
// $FlowFixMe[unclear-type]
111113
const anyValue: any = value;
112114
return {
113115
...emptyAnimation,

packages/react-native/Libraries/Animated/nodes/AnimatedInterpolation.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow
7+
* @flow strict-local
88
* @format
99
*/
1010

@@ -49,7 +49,7 @@ export type InterpolationConfigType<
4949
function createNumericInterpolation(
5050
config: InterpolationConfigType<number>,
5151
): (input: number) => number {
52-
const outputRange: ReadonlyArray<number> = config.outputRange as any;
52+
const outputRange: ReadonlyArray<number> = config.outputRange;
5353
const inputRange = config.inputRange;
5454

5555
const easing = config.easing || Easing.linear;
@@ -84,6 +84,7 @@ function createNumericInterpolation(
8484
easing,
8585
extrapolateLeft,
8686
extrapolateRight,
87+
// $FlowFixMe[unclear-type]
8788
) as any;
8889
};
8990
}
@@ -203,6 +204,7 @@ function mapStringToNumericComponents(
203204
const components: Array<string | number> = [];
204205
let lastMatchEnd = 0;
205206
let match: RegExp$matchResult;
207+
// $FlowFixMe[unclear-type]
206208
while ((match = numericComponentRegex.exec(input) as any) != null) {
207209
if (match.index > lastMatchEnd) {
208210
components.push(input.substring(lastMatchEnd, match.index));
@@ -468,12 +470,16 @@ export default class AnimatedInterpolation<
468470
if (!this._interpolation) {
469471
const config = this._config;
470472
if (config.outputRange && typeof config.outputRange[0] === 'string') {
473+
// $FlowFixMe[unclear-type]
471474
this._interpolation = createStringInterpolation(config as any) as any;
472475
} else if (typeof config.outputRange[0] === 'object') {
473476
this._interpolation = createPlatformColorInterpolation(
477+
// $FlowFixMe[unclear-type]
474478
config as any,
479+
// $FlowFixMe[unclear-type]
475480
) as any;
476481
} else {
482+
// $FlowFixMe[unclear-type]
477483
this._interpolation = createNumericInterpolation(config as any) as any;
478484
}
479485
}
@@ -510,6 +516,7 @@ export default class AnimatedInterpolation<
510516
super.__detach();
511517
}
512518

519+
// $FlowFixMe[unclear-type]
513520
__getNativeConfig(): any {
514521
if (__DEV__) {
515522
validateInterpolation(this._config);
@@ -528,6 +535,7 @@ export default class AnimatedInterpolation<
528535
} else {
529536
return NativeAnimatedHelper.transformDataType(value);
530537
}
538+
// $FlowFixMe[unclear-type]
531539
}) as any;
532540
} else if (typeof outputRange[0] === 'object') {
533541
outputType = 'platform_color';

packages/react-native/Libraries/Animated/nodes/AnimatedNode.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow
7+
* @flow strict-local
88
* @format
99
*/
1010

@@ -64,7 +64,9 @@ export default class AnimatedNode {
6464
this.__nativeTag = undefined;
6565
}
6666
}
67+
// $FlowFixMe[unclear-type]
6768
__getValue(): any {}
69+
// $FlowFixMe[unclear-type]
6870
__getAnimatedValue(): any {
6971
return this.__getValue();
7072
}
@@ -112,6 +114,7 @@ export default class AnimatedNode {
112114
*
113115
* See https://reactnative.dev/docs/animatedvalue#addlistener
114116
*/
117+
// $FlowFixMe[unclear-type]
115118
addListener(callback: (value: any) => unknown): string {
116119
const id = String(_uniqueId++);
117120
this._listeners.set(id, callback);
@@ -216,6 +219,7 @@ export default class AnimatedNode {
216219
if (this._platformConfig) {
217220
config.platformConfig = this._platformConfig;
218221
}
222+
// $FlowFixMe[sketchy-null-bool]
219223
if (this.__disableBatchingForNativeCreate) {
220224
config.disableBatchingForNativeCreate = true;
221225
}
@@ -224,6 +228,7 @@ export default class AnimatedNode {
224228
return nativeTag;
225229
}
226230

231+
// $FlowFixMe[unclear-type]
227232
__getNativeConfig(): Object {
228233
throw new Error(
229234
'This JS animated node type cannot be used as native animated node',

packages/react-native/Libraries/Animated/nodes/AnimatedProps.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow
7+
* @flow strict-local
88
* @format
99
*/
1010

@@ -119,6 +119,7 @@ export default class AnimatedProps extends AnimatedNode {
119119
this._rootTag = rootTag;
120120
}
121121

122+
// $FlowFixMe[unclear-type]
122123
__getValue(): Object {
123124
const props: {[string]: unknown} = {};
124125

@@ -144,6 +145,7 @@ export default class AnimatedProps extends AnimatedNode {
144145
* `staticProps` object, except with animated nodes for any props that were
145146
* created by this `AnimatedProps` instance.
146147
*/
148+
// $FlowFixMe[unclear-type]
147149
__getValueWithStaticProps(staticProps: Object): Object {
148150
const props: {[string]: unknown} = {...staticProps};
149151

@@ -196,6 +198,7 @@ export default class AnimatedProps extends AnimatedNode {
196198
return tuples;
197199
}
198200

201+
// $FlowFixMe[unclear-type]
199202
__getAnimatedValue(): Object {
200203
const props: {[string]: unknown} = {};
201204

@@ -356,6 +359,7 @@ export default class AnimatedProps extends AnimatedNode {
356359
}
357360
}
358361

362+
// $FlowFixMe[unclear-type]
359363
__getNativeConfig(): Object {
360364
const platformConfig = this.__getPlatformConfig();
361365
const propsConfig: {[string]: number} = {};

0 commit comments

Comments
 (0)