From 5fc24844409bf51ca83a10903ebbf89621750ef5 Mon Sep 17 00:00:00 2001 From: Iwo Plaza Date: Fri, 28 Feb 2025 06:33:21 -0800 Subject: [PATCH] Align useAnimatedValue with OSS types (#49643) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/49643 ## Motivation Modernising the RN codebase to allow for modern Flow tooling to process it. ## This diff Aligns `useAnimatedValue.js` with its manual .d.ts types. Changelog: [Internal] Reviewed By: huntie Differential Revision: D70096210 fbshipit-source-id: c3cd517eccf1cb68400772ddde6e5891861c927d --- .../react-native/Libraries/Animated/AnimatedExports.js.flow | 2 ++ packages/react-native/Libraries/Animated/useAnimatedValue.js | 4 +--- .../Libraries/__tests__/__snapshots__/public-api-test.js.snap | 3 ++- scripts/build/build-types/buildTypes.js | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/react-native/Libraries/Animated/AnimatedExports.js.flow b/packages/react-native/Libraries/Animated/AnimatedExports.js.flow index 51a1b68186f..a487448e247 100644 --- a/packages/react-native/Libraries/Animated/AnimatedExports.js.flow +++ b/packages/react-native/Libraries/Animated/AnimatedExports.js.flow @@ -24,6 +24,8 @@ export {default as Node} from './nodes/AnimatedNode'; export {default as Value} from './nodes/AnimatedValue'; export {default as ValueXY} from './nodes/AnimatedValueXY'; +export type {AnimatedValueConfig as AnimatedConfig} from './nodes/AnimatedValue'; + export const add = AnimatedImplementation.add; export const attachNativeEvent = AnimatedImplementation.attachNativeEvent; export const createAnimatedComponent = diff --git a/packages/react-native/Libraries/Animated/useAnimatedValue.js b/packages/react-native/Libraries/Animated/useAnimatedValue.js index 0a430ed5c3c..4809135697b 100644 --- a/packages/react-native/Libraries/Animated/useAnimatedValue.js +++ b/packages/react-native/Libraries/Animated/useAnimatedValue.js @@ -8,14 +8,12 @@ * @format */ -import type {AnimatedValueConfig} from './nodes/AnimatedValue'; - import Animated from './Animated'; import {useRef} from 'react'; export default function useAnimatedValue( initialValue: number, - config?: ?AnimatedValueConfig, + config?: ?Animated.AnimatedConfig, ): Animated.Value { const ref = useRef(null); if (ref.current == null) { diff --git a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap index e932154065a..801fcc7d7ad 100644 --- a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap +++ b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap @@ -172,6 +172,7 @@ export { default as Interpolation } from \\"./nodes/AnimatedInterpolation\\"; export { default as Node } from \\"./nodes/AnimatedNode\\"; export { default as Value } from \\"./nodes/AnimatedValue\\"; export { default as ValueXY } from \\"./nodes/AnimatedValueXY\\"; +export type { AnimatedValueConfig as AnimatedConfig } from \\"./nodes/AnimatedValue\\"; declare export const add: $FlowFixMe; declare export const attachNativeEvent: $FlowFixMe; declare export const createAnimatedComponent: $FlowFixMe; @@ -1006,7 +1007,7 @@ exports[`public API should not change unintentionally Libraries/Animated/useAnim exports[`public API should not change unintentionally Libraries/Animated/useAnimatedValue.js 1`] = ` "declare export default function useAnimatedValue( initialValue: number, - config?: ?AnimatedValueConfig + config?: ?Animated.AnimatedConfig ): Animated.Value; " `; diff --git a/scripts/build/build-types/buildTypes.js b/scripts/build/build-types/buildTypes.js index a305eac59e0..e9579bae287 100644 --- a/scripts/build/build-types/buildTypes.js +++ b/scripts/build/build-types/buildTypes.js @@ -29,6 +29,7 @@ const ENTRY_POINTS = [ 'packages/react-native/Libraries/ActionSheetIOS/ActionSheetIOS.js', 'packages/react-native/Libraries/Alert/Alert.js', 'packages/react-native/Libraries/Animated/Animated.js', + 'packages/react-native/Libraries/Animated/useAnimatedValue.js', 'packages/react-native/Libraries/AppState/AppState.js', 'packages/react-native/Libraries/BatchedBridge/NativeModules.js', 'packages/react-native/Libraries/Blob/Blob.js',