Skip to content

Commit f47bc65

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. Changelog: [Internal] Reviewed By: javache Differential Revision: D113763788
1 parent 1461331 commit f47bc65

9 files changed

Lines changed: 132 additions & 39 deletions

File tree

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

Lines changed: 25 additions & 3 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,16 +155,19 @@ 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

156168
if (config == null) {
157169
console.warn('Animated.event now requires a second argument for options');
170+
// $FlowFixMe[reassign-const]
158171
config = {useNativeDriver: false};
159172
}
160173

@@ -166,14 +179,17 @@ export class AnimatedEvent {
166179
this.__platformConfig = config.platformConfig;
167180
}
168181

182+
// $FlowFixMe[unclear-type]
169183
__addListener(callback: Function): void {
170184
this._listeners.push(callback);
171185
}
172186

187+
// $FlowFixMe[unclear-type]
173188
__removeListener(callback: Function): void {
174189
this._listeners = this._listeners.filter(listener => listener !== callback);
175190
}
176191

192+
// $FlowFixMe[unclear-type]
177193
__attach(viewRef: any, eventName: string): void {
178194
invariant(
179195
this.__isNative,
@@ -188,6 +204,7 @@ export class AnimatedEvent {
188204
);
189205
}
190206

207+
// $FlowFixMe[unclear-type]
191208
__detach(viewTag: any, eventName: string): void {
192209
invariant(
193210
this.__isNative,
@@ -197,10 +214,12 @@ export class AnimatedEvent {
197214
this._attachedEvent && this._attachedEvent.detach();
198215
}
199216

217+
// $FlowFixMe[unclear-type]
200218
__getHandler(): (...args: any) => void {
201219
if (this.__isNative) {
202220
if (__DEV__) {
203221
let validatedMapping = false;
222+
// $FlowFixMe[unclear-type]
204223
return (...args: any) => {
205224
if (!validatedMapping) {
206225
validateMapping(this._argMapping, args);
@@ -214,6 +233,7 @@ export class AnimatedEvent {
214233
}
215234

216235
let validatedMapping = false;
236+
// $FlowFixMe[unclear-type]
217237
return (...args: any) => {
218238
if (__DEV__ && !validatedMapping) {
219239
validateMapping(this._argMapping, args);
@@ -222,6 +242,7 @@ export class AnimatedEvent {
222242

223243
const traverse = (
224244
recMapping: ?(Mapping | AnimatedValue),
245+
// $FlowFixMe[unclear-type]
225246
recEvt: any,
226247
) => {
227248
if (recMapping instanceof AnimatedValue) {
@@ -250,6 +271,7 @@ export class AnimatedEvent {
250271
};
251272
}
252273

274+
// $FlowFixMe[unclear-type]
253275
_callListeners = (...args: any) => {
254276
this._listeners.forEach(listener => listener(...args));
255277
};

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 & 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',

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)