mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Type Animated.event() as an event handler instead of any (#57991)
Summary: Pull Request resolved: https://github.com/react/react-native/pull/57991 Addresses a type narrowness regression (Strict API vs legacy manual types), raised by user feedback: https://github.com/react-native-community/discussions-and-proposals/discussions/1015#discussioncomment-18053943 Changelog: [General][Fixed] - **Animated**: `Animated.event()` is typed as an event handler rather than `any` Reviewed By: vzaidman Differential Revision: D116440620 fbshipit-source-id: 4ba629c511fcf28981700d1bc841a4ce8dcf17f8
This commit is contained in:
1 parent
2ce2c0794b
commit
3eb330a365
4 files changed
+10
-6
No files matched your search
@@ -197,7 +197,7 @@ export class AnimatedEvent {
|
||||
this._attachedEvent && this._attachedEvent.detach();
|
||||
}
|
||||
|
||||
__getHandler(): any | ((...args: any) => void) {
|
||||
__getHandler(): (...args: any) => void {
|
||||
if (this.__isNative) {
|
||||
if (__DEV__) {
|
||||
let validatedMapping = false;
|
||||
|
||||
@@ -576,10 +576,14 @@ function unforkEventImpl(
|
||||
}
|
||||
}
|
||||
|
||||
const eventImpl = function <T>(
|
||||
// NOTE: With `useNativeDriver: true` this returns an `AnimatedEvent` instance
|
||||
// rather than a callable handler. That object is only ever meant to be handed
|
||||
// straight back to an animated component's event prop, so the declared type
|
||||
// describes the handler shape both branches are consumed as.
|
||||
const eventImpl: <T>(
|
||||
argMapping: ReadonlyArray<?Mapping>,
|
||||
config: EventConfig<T>,
|
||||
): any {
|
||||
) => (...args: Array<any>) => void = function (argMapping, config): any {
|
||||
const animatedEvent = new AnimatedEvent(argMapping, config);
|
||||
if (animatedEvent.__isNative) {
|
||||
return animatedEvent;
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated SignedSource<<44990574a74bcc122718d4f6142db8cd>>
|
||||
* @generated SignedSource<<5335b26453a7d4d5bb9b7d54ded6218f>>
|
||||
*
|
||||
* This file was generated by scripts/js-api/build-types/index.js.
|
||||
*/
|
||||
@@ -232,7 +232,7 @@ declare const event: typeof $$AnimatedImplementation.event
|
||||
declare const eventImpl: <T>(
|
||||
argMapping: ReadonlyArray<Mapping | null | undefined>,
|
||||
config: EventConfig<T>,
|
||||
) => any
|
||||
) => (...args: Array<any>) => void
|
||||
declare const findNodeHandle: typeof $$ReactFabric.findNodeHandle
|
||||
declare const flatten: typeof $$flattenStyle
|
||||
declare const forkEvent: typeof $$AnimatedImplementation.forkEvent
|
||||
|
||||
+1
-1
@@ -369,7 +369,7 @@ describe('Native Animated', () => {
|
||||
const value = new Animated.Value(0);
|
||||
value.__makeNative();
|
||||
const listener = jest.fn();
|
||||
const event = Animated.event([{nativeEvent: {foo: value}}], {
|
||||
const event = new Animated.Event([{nativeEvent: {foo: value}}], {
|
||||
useNativeDriver: true,
|
||||
listener,
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user