Skip to content

Commit 3eab03d

Browse files
huntiemeta-codesync[bot]
authored andcommitted
Type Animated.Value.addListener callback (#57992)
Summary: Pull Request resolved: #57992 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.Value.addListener()` types its callback payload as `{value: number}` rather than `any` Reviewed By: vzaidman Differential Revision: D116440622 fbshipit-source-id: b85c7d7fbd8e81cc2e953c9a6f60701f3991ba6e
1 parent 3eb330a commit 3eab03d

3 files changed

Lines changed: 25 additions & 24 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {PlatformConfig} from '../AnimatedPlatformConfig';
1313
import NativeAnimatedHelper from '../../../src/private/animated/NativeAnimatedHelper';
1414
import invariant from 'invariant';
1515

16-
type ValueListenerCallback = (state: {value: number, ...}) => unknown;
16+
export type ValueListenerCallback = (state: {value: number}) => unknown;
1717

1818
export type AnimatedNodeConfig = Readonly<{
1919
debugID?: string,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type {
1717
InterpolationConfigType,
1818
} from './AnimatedInterpolation';
1919
import type AnimatedNode from './AnimatedNode';
20-
import type {AnimatedNodeConfig} from './AnimatedNode';
20+
import type {AnimatedNodeConfig, ValueListenerCallback} from './AnimatedNode';
2121
import type AnimatedTracking from './AnimatedTracking';
2222

2323
import NativeAnimatedHelper from '../../../src/private/animated/NativeAnimatedHelper';
@@ -138,7 +138,7 @@ export default class AnimatedValue extends AnimatedWithChildren {
138138
}
139139
}
140140

141-
addListener(callback: (value: any) => unknown): string {
141+
addListener(callback: ValueListenerCallback): string {
142142
const id = super.addListener(callback);
143143
this._listenerCount++;
144144
if (this.__isNative) {

packages/react-native/ReactNativeApi.d.ts

Lines changed: 22 additions & 21 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-
* @generated SignedSource<<5335b26453a7d4d5bb9b7d54ded6218f>>
7+
* @generated SignedSource<<aa2e1e5d4537b814b54eaaeafe35469c>>
88
*
99
* This file was generated by scripts/js-api/build-types/index.js.
1010
*/
@@ -1401,7 +1401,7 @@ declare class AnimatedTracking_default extends AnimatedNode_default {
14011401
update(): void
14021402
}
14031403
declare class AnimatedValue_default extends AnimatedWithChildren_default {
1404-
addListener(callback: (value: any) => unknown): string
1404+
addListener(callback: ValueListenerCallback): string
14051405
animate(
14061406
animation: Animation_default,
14071407
callback: EndCallback | null | undefined,
@@ -5404,6 +5404,7 @@ declare type UTFSequence = typeof UTFSequence
54045404
declare type Value = null | {
54055405
horizontal: boolean
54065406
}
5407+
declare type ValueListenerCallback = (state: { value: number }) => unknown
54075408
declare type ValueOfUnion<T, K> = T extends any
54085409
? K extends keyof T
54095410
? T[K]
@@ -5730,7 +5731,7 @@ export {
57305731
AlertOptions, // 8a116d2a
57315732
AlertType, // 5ab91217
57325733
AndroidKeyboardEvent, // e03becc8
5733-
Animated, // f23abee5
5734+
Animated, // c8741f58
57345735
AppConfig, // 35c0ca70
57355736
AppRegistry, // 1e8c5a00
57365737
AppState, // 12012be5
@@ -5744,8 +5745,8 @@ export {
57445745
BackPressEventName, // 4620fb76
57455746
BlurEvent, // 4ba4f941
57465747
BoxShadowValue, // b679703f
5747-
Button, // bc8f6464
5748-
ButtonInstance, // d94b4241
5748+
Button, // 586b24c2
5749+
ButtonInstance, // e3c42339
57495750
ButtonProps, // 21c5780c
57505751
Clipboard, // 41addb89
57515752
CodegenTypes, // ab4986cc
@@ -5782,9 +5783,9 @@ export {
57825783
EventSubscription, // b8d084aa
57835784
ExtendedExceptionData, // 5a6ccf5a
57845785
FilterFunction, // bf24c0e3
5785-
FlatList, // e1b005c7
5786-
FlatListInstance, // 2d1d8e45
5787-
FlatListProps, // 94fa2dc7
5786+
FlatList, // 2a814748
5787+
FlatListInstance, // 696cc805
5788+
FlatListProps, // 6d5e2d1f
57885789
FocusEvent, // 850f1517
57895790
FontVariant, // 7c7558bb
57905791
GestureResponderEvent, // 14d3e77a
@@ -5925,18 +5926,18 @@ export {
59255926
ScrollEvent, // d7abdd0a
59265927
ScrollResponderType, // ba188eae
59275928
ScrollToLocationParamsType, // d7ecdad1
5928-
ScrollView, // 066a8597
5929+
ScrollView, // 66fa774d
59295930
ScrollViewImperativeMethods, // 904c66fd
59305931
ScrollViewInstance, // ccf4f341
5931-
ScrollViewProps, // b62913d1
5932+
ScrollViewProps, // 678e4360
59325933
ScrollViewPropsAndroid, // 02f3df2e
59335934
ScrollViewPropsIOS, // 807cb4f6
59345935
ScrollViewScrollToOptions, // 3313411e
59355936
SectionBase, // 9f13db00
5936-
SectionList, // ee3e7972
5937+
SectionList, // 4a8d5792
59375938
SectionListData, // 1a4de01a
5938-
SectionListInstance, // c9b991fe
5939-
SectionListProps, // 0e933318
5939+
SectionListInstance, // b6326f35
5940+
SectionListProps, // d0058bb4
59405941
SectionListRenderItem, // 715b2086
59415942
SectionListRenderItemInfo, // 4a48a922
59425943
Separators, // 6a45f7e3
@@ -5953,7 +5954,7 @@ export {
59535954
StatusBarProps, // c2a44d88
59545955
StatusBarStyle, // 78f53eea
59555956
StyleProp, // fa0e9b4a
5956-
StyleSheet, // daba2860
5957+
StyleSheet, // a6a3620c
59575958
SubmitBehavior, // c4ddf490
59585959
Switch, // f495bab3
59595960
SwitchChangeEvent, // 899635b1
@@ -5989,9 +5990,9 @@ export {
59895990
TouchableNativeFeedback, // fe739e82
59905991
TouchableNativeFeedbackInstance, // 0877e3e4
59915992
TouchableNativeFeedbackProps, // 1d0c2f30
5992-
TouchableOpacity, // fe716ffc
5993+
TouchableOpacity, // 3eccd75e
59935994
TouchableOpacityInstance, // b186055b
5994-
TouchableOpacityProps, // a3b32b69
5995+
TouchableOpacityProps, // dd9e3393
59955996
TouchableWithoutFeedback, // ed159ba7
59965997
TouchableWithoutFeedbackProps, // e613ed05
59975998
TransformsStyle, // 65e70f18
@@ -6009,20 +6010,20 @@ export {
60096010
VirtualViewMode, // 6be59722
60106011
VirtualizedList, // 68c7345e
60116012
VirtualizedListInstance, // 423ee7c0
6012-
VirtualizedListProps, // f51f4a42
6013+
VirtualizedListProps, // 743d6082
60136014
VirtualizedSectionList, // 9fd9cd61
60146015
VirtualizedSectionListInstance, // 12b706d5
6015-
VirtualizedSectionListProps, // 8210f30a
6016+
VirtualizedSectionListProps, // 99c0a403
60166017
WrapperComponentProvider, // 9ef54e61
60176018
codegenNativeCommands, // 628a7c0a
60186019
codegenNativeComponent, // 32a1bca6
60196020
findNodeHandle, // 93f80214
60206021
processColor, // 6e877698
60216022
registerCallableModule, // 839c8cfe
60226023
requireNativeComponent, // aa36a6dd
6023-
useAnimatedColor, // a9dffd9f
6024-
useAnimatedValue, // 25733d13
6025-
useAnimatedValueXY, // 04c70878
6024+
useAnimatedColor, // 31a919f9
6025+
useAnimatedValue, // 3eb9d3c0
6026+
useAnimatedValueXY, // b434ca0f
60266027
useColorScheme, // d585efdb
60276028
usePressability, // 782138ed
60286029
useWindowDimensions, // bb4b683f

0 commit comments

Comments
 (0)