Skip to content

Commit 97324ab

Browse files
j-piaseckifacebook-github-bot
authored andcommitted
Type Animated.event listener argument (#50390)
Summary: Pull Request resolved: #50390 Changelog: [Internal] Reviewed By: huntie Differential Revision: D72151986 fbshipit-source-id: 26c9b6dff669fac6fcb8db1f6a0b23648f6f4afb
1 parent bff5c30 commit 97324ab

5 files changed

Lines changed: 17 additions & 11 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
'use strict';
1212

13+
import type {NativeSyntheticEvent} from '../Types/CoreEventTypes';
1314
import type {PlatformConfig} from './AnimatedPlatformConfig';
1415

1516
import NativeAnimatedHelper from '../../src/private/animated/NativeAnimatedHelper';
@@ -22,8 +23,8 @@ export type Mapping =
2223
| {[key: string]: Mapping, ...}
2324
| AnimatedValue
2425
| AnimatedValueXY;
25-
export type EventConfig = {
26-
listener?: ?Function,
26+
export type EventConfig<T> = {
27+
listener?: ?(NativeSyntheticEvent<T>) => mixed,
2728
useNativeDriver: boolean,
2829
platformConfig?: PlatformConfig,
2930
};
@@ -150,7 +151,7 @@ export class AnimatedEvent {
150151
__isNative: boolean;
151152
__platformConfig: ?PlatformConfig;
152153

153-
constructor(argMapping: $ReadOnlyArray<?Mapping>, config: EventConfig) {
154+
constructor(argMapping: $ReadOnlyArray<?Mapping>, config: EventConfig<any>) {
154155
this._argMapping = argMapping;
155156

156157
if (config == null) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,9 @@ function unforkEvent(
540540
}
541541
}
542542

543-
const event = function (
543+
const event = function <T>(
544544
argMapping: $ReadOnlyArray<?Mapping>,
545-
config: EventConfig,
545+
config: EventConfig<T>,
546546
): any {
547547
const animatedEvent = new AnimatedEvent(argMapping, config);
548548
if (animatedEvent.__isNative) {

packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ exports[`public API should not change unintentionally Libraries/Animated/Animate
128128
| { [key: string]: Mapping, ... }
129129
| AnimatedValue
130130
| AnimatedValueXY;
131-
export type EventConfig = {
132-
listener?: ?Function,
131+
export type EventConfig<T> = {
132+
listener?: ?(NativeSyntheticEvent<T>) => mixed,
133133
useNativeDriver: boolean,
134134
platformConfig?: PlatformConfig,
135135
};
@@ -140,7 +140,10 @@ declare export function attachNativeEvent(
140140
platformConfig: ?PlatformConfig
141141
): { detach: () => void };
142142
declare export class AnimatedEvent {
143-
constructor(argMapping: $ReadOnlyArray<?Mapping>, config: EventConfig): void;
143+
constructor(
144+
argMapping: $ReadOnlyArray<?Mapping>,
145+
config: EventConfig<any>
146+
): void;
144147
}
145148
"
146149
`;
@@ -278,9 +281,9 @@ declare function unforkEvent(
278281
event: ?AnimatedEvent | ?Function,
279282
listener: Function
280283
): void;
281-
declare const event: (
284+
declare const event: <T>(
282285
argMapping: $ReadOnlyArray<?Mapping>,
283-
config: EventConfig
286+
config: EventConfig<T>
284287
) => any;
285288
type AnimatedNumeric =
286289
| AnimatedAddition
@@ -9655,6 +9658,7 @@ export type {
96559658
MouseEvent,
96569659
NativeMouseEvent,
96579660
NativePointerEvent,
9661+
NativeScrollEvent,
96589662
NativeSyntheticEvent,
96599663
NativeTouchEvent,
96609664
NativeUIEvent,

packages/react-native/index.js.flow

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ export type {
389389
MouseEvent,
390390
NativeMouseEvent,
391391
NativePointerEvent,
392+
NativeScrollEvent,
392393
NativeSyntheticEvent,
393394
NativeTouchEvent,
394395
NativeUIEvent,

packages/react-native/src/private/animated/NativeAnimatedHelper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ function assertNativeAnimatedModule(): void {
384384
let _warnedMissingNativeAnimated = false;
385385

386386
function shouldUseNativeDriver(
387-
config: $ReadOnly<{...AnimationConfig, ...}> | EventConfig,
387+
config: $ReadOnly<{...AnimationConfig, ...}> | EventConfig<mixed>,
388388
): boolean {
389389
if (config.useNativeDriver == null) {
390390
console.warn(

0 commit comments

Comments
 (0)