Skip to content

Commit cd36325

Browse files
rubennortemeta-codesync[bot]
authored andcommitted
Make remaining library modules Flow strict-local (#57727)
Summary: Pull Request resolved: #57727 Upgrade the remaining Animated and platform-specific React Native library modules from `flow` to `flow strict-local`. Public type signatures and runtime behavior are unchanged; internal `any` usages that cannot be typed precisely are marked with scoped `$FlowFixMe[unclear-type]`. Changelog: [Internal] Reviewed By: javache Differential Revision: D113763788
1 parent 0fcf2fa commit cd36325

8 files changed

Lines changed: 89 additions & 26 deletions

File tree

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

Lines changed: 32 additions & 9 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

@@ -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>,
@@ -56,13 +57,20 @@ export function attachNativeEventImpl(
5657
}
5758
};
5859

60+
const firstMapping = argMapping[0];
61+
const nativeEventMapping =
62+
firstMapping != null &&
63+
!(firstMapping instanceof AnimatedValue) &&
64+
!(firstMapping instanceof AnimatedValueXY)
65+
? firstMapping.nativeEvent
66+
: null;
5967
invariant(
60-
argMapping[0] && argMapping[0].nativeEvent,
68+
nativeEventMapping != null,
6169
'Native driven events only support animated values contained inside `nativeEvent`.',
6270
);
6371

6472
// Assume that the event containing `nativeEvent` is always the first argument.
65-
traverse(argMapping[0].nativeEvent, []);
73+
traverse(nativeEventMapping, []);
6674

6775
const viewTag = findNodeHandle(viewRef);
6876
if (viewTag != null) {
@@ -91,7 +99,9 @@ export function attachNativeEventImpl(
9199
};
92100
}
93101

102+
// $FlowFixMe[unclear-type]
94103
function validateMapping(argMapping: ReadonlyArray<?Mapping>, args: any) {
104+
// $FlowFixMe[unclear-type]
95105
const validate = (recMapping: ?Mapping, recEvt: any, key: string) => {
96106
if (recMapping instanceof AnimatedValue) {
97107
invariant(
@@ -145,35 +155,42 @@ function validateMapping(argMapping: ReadonlyArray<?Mapping>, args: any) {
145155

146156
export class AnimatedEvent {
147157
_argMapping: ReadonlyArray<?Mapping>;
158+
// $FlowFixMe[unclear-type]
148159
_listeners: Array<Function> = [];
149160
_attachedEvent: ?{detach: () => void, ...};
150161
__isNative: boolean;
151162
__platformConfig: ?PlatformConfig;
152163

164+
// $FlowFixMe[unclear-type]
153165
constructor(argMapping: ReadonlyArray<?Mapping>, config: EventConfig<any>) {
154166
this._argMapping = argMapping;
155167

156-
if (config == null) {
168+
let resolvedConfig = config;
169+
if (resolvedConfig == null) {
157170
console.warn('Animated.event now requires a second argument for options');
158-
config = {useNativeDriver: false};
171+
resolvedConfig = {useNativeDriver: false};
159172
}
160173

161-
if (config.listener) {
162-
this.__addListener(config.listener);
174+
if (resolvedConfig.listener) {
175+
this.__addListener(resolvedConfig.listener);
163176
}
164177
this._attachedEvent = null;
165-
this.__isNative = NativeAnimatedHelper.shouldUseNativeDriver(config);
166-
this.__platformConfig = config.platformConfig;
178+
this.__isNative =
179+
NativeAnimatedHelper.shouldUseNativeDriver(resolvedConfig);
180+
this.__platformConfig = resolvedConfig.platformConfig;
167181
}
168182

183+
// $FlowFixMe[unclear-type]
169184
__addListener(callback: Function): void {
170185
this._listeners.push(callback);
171186
}
172187

188+
// $FlowFixMe[unclear-type]
173189
__removeListener(callback: Function): void {
174190
this._listeners = this._listeners.filter(listener => listener !== callback);
175191
}
176192

193+
// $FlowFixMe[unclear-type]
177194
__attach(viewRef: any, eventName: string): void {
178195
invariant(
179196
this.__isNative,
@@ -188,6 +205,7 @@ export class AnimatedEvent {
188205
);
189206
}
190207

208+
// $FlowFixMe[unclear-type]
191209
__detach(viewTag: any, eventName: string): void {
192210
invariant(
193211
this.__isNative,
@@ -197,10 +215,12 @@ export class AnimatedEvent {
197215
this._attachedEvent && this._attachedEvent.detach();
198216
}
199217

218+
// $FlowFixMe[unclear-type]
200219
__getHandler(): (...args: any) => void {
201220
if (this.__isNative) {
202221
if (__DEV__) {
203222
let validatedMapping = false;
223+
// $FlowFixMe[unclear-type]
204224
return (...args: any) => {
205225
if (!validatedMapping) {
206226
validateMapping(this._argMapping, args);
@@ -214,6 +234,7 @@ export class AnimatedEvent {
214234
}
215235

216236
let validatedMapping = false;
237+
// $FlowFixMe[unclear-type]
217238
return (...args: any) => {
218239
if (__DEV__ && !validatedMapping) {
219240
validateMapping(this._argMapping, args);
@@ -222,6 +243,7 @@ export class AnimatedEvent {
222243

223244
const traverse = (
224245
recMapping: ?(Mapping | AnimatedValue),
246+
// $FlowFixMe[unclear-type]
225247
recEvt: any,
226248
) => {
227249
if (recMapping instanceof AnimatedValue) {
@@ -250,6 +272,7 @@ export class AnimatedEvent {
250272
};
251273
}
252274

275+
// $FlowFixMe[unclear-type]
253276
_callListeners = (...args: any) => {
254277
this._listeners.forEach(listener => listener(...args));
255278
};

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

Lines changed: 23 additions & 9 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

@@ -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,10 @@ const springImpl = function (
184186
configuration: SpringAnimationConfig,
185187
callback?: ?EndCallback,
186188
): void {
187-
callback = _combineCallbacks(callback, configuration);
189+
const combinedCallback = _combineCallbacks(callback, configuration);
190+
// $FlowFixMe[unclear-type]
188191
const singleValue: any = animatedValue;
192+
// $FlowFixMe[unclear-type]
189193
const singleConfig: any = configuration;
190194
singleValue.stopTracking();
191195
if (configuration.toValue instanceof AnimatedNode) {
@@ -195,11 +199,11 @@ const springImpl = function (
195199
configuration.toValue,
196200
SpringAnimation,
197201
singleConfig,
198-
callback,
202+
combinedCallback,
199203
),
200204
);
201205
} else {
202-
singleValue.animate(new SpringAnimation(singleConfig), callback);
206+
singleValue.animate(new SpringAnimation(singleConfig), combinedCallback);
203207
}
204208
};
205209
return (
@@ -241,8 +245,10 @@ const timingImpl = function (
241245
configuration: TimingAnimationConfig,
242246
callback?: ?EndCallback,
243247
): void {
244-
callback = _combineCallbacks(callback, configuration);
248+
const combinedCallback = _combineCallbacks(callback, configuration);
249+
// $FlowFixMe[unclear-type]
245250
const singleValue: any = animatedValue;
251+
// $FlowFixMe[unclear-type]
246252
const singleConfig: any = configuration;
247253
singleValue.stopTracking();
248254
if (configuration.toValue instanceof AnimatedNode) {
@@ -252,11 +258,11 @@ const timingImpl = function (
252258
configuration.toValue,
253259
TimingAnimation,
254260
singleConfig,
255-
callback,
261+
combinedCallback,
256262
),
257263
);
258264
} else {
259-
singleValue.animate(new TimingAnimation(singleConfig), callback);
265+
singleValue.animate(new TimingAnimation(singleConfig), combinedCallback);
260266
}
261267
};
262268

@@ -299,11 +305,13 @@ const decayImpl = function (
299305
configuration: DecayAnimationConfig,
300306
callback?: ?EndCallback,
301307
): void {
302-
callback = _combineCallbacks(callback, configuration);
308+
const combinedCallback = _combineCallbacks(callback, configuration);
309+
// $FlowFixMe[unclear-type]
303310
const singleValue: any = animatedValue;
311+
// $FlowFixMe[unclear-type]
304312
const singleConfig: any = configuration;
305313
singleValue.stopTracking();
306-
singleValue.animate(new DecayAnimation(singleConfig), callback);
314+
singleValue.animate(new DecayAnimation(singleConfig), combinedCallback);
307315
};
308316

309317
return (
@@ -551,8 +559,11 @@ const loopImpl = function (
551559
};
552560

553561
function forkEventImpl(
562+
// $FlowFixMe[unclear-type]
554563
event: ?AnimatedEvent | ?Function,
564+
// $FlowFixMe[unclear-type]
555565
listener: Function,
566+
// $FlowFixMe[unclear-type]
556567
): AnimatedEvent | Function {
557568
if (!event) {
558569
return listener;
@@ -568,7 +579,9 @@ function forkEventImpl(
568579
}
569580

570581
function unforkEventImpl(
582+
// $FlowFixMe[unclear-type]
571583
event: ?AnimatedEvent | ?Function,
584+
// $FlowFixMe[unclear-type]
572585
listener: Function,
573586
): void {
574587
if (event && event instanceof AnimatedEvent) {
@@ -583,6 +596,7 @@ function unforkEventImpl(
583596
const eventImpl: <T>(
584597
argMapping: ReadonlyArray<?Mapping>,
585598
config: EventConfig<T>,
599+
// $FlowFixMe[unclear-type]
586600
) => (...args: Array<any>) => void = function (argMapping, config): any {
587601
const animatedEvent = new AnimatedEvent(argMapping, config);
588602
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 & 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

@@ -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,14 +219,15 @@ export default class AnimatedNode {
216219
if (this._platformConfig) {
217220
config.platformConfig = this._platformConfig;
218221
}
219-
if (this.__disableBatchingForNativeCreate) {
222+
if (this.__disableBatchingForNativeCreate === true) {
220223
config.disableBatchingForNativeCreate = true;
221224
}
222225
NativeAnimatedHelper.API.createAnimatedNode(nativeTag, config);
223226
}
224227
return nativeTag;
225228
}
226229

230+
// $FlowFixMe[unclear-type]
227231
__getNativeConfig(): Object {
228232
throw new Error(
229233
'This JS animated node type cannot be used as native animated node',

0 commit comments

Comments
 (0)