diff --git a/packages/react-native/Libraries/Animated/createAnimatedComponent.js b/packages/react-native/Libraries/Animated/createAnimatedComponent.js index bb4ffd331cba..d922718c6729 100644 --- a/packages/react-native/Libraries/Animated/createAnimatedComponent.js +++ b/packages/react-native/Libraries/Animated/createAnimatedComponent.js @@ -36,7 +36,7 @@ export type StrictAnimatedProps = $ReadOnly<{ }>; export type AnimatedComponentType = component( - ref: React.RefSetter, + ref?: React.RefSetter, ...AnimatedProps ); @@ -45,29 +45,41 @@ export type StrictAnimatedComponentType< +Instance = mixed, > = component(ref: React.RefSetter, ...StrictAnimatedProps); -export default function createAnimatedComponent( - Component: component(ref: React.RefSetter, ...TProps), -): AnimatedComponentType { +export default function createAnimatedComponent< + TInstance: React.ComponentType, +>( + Component: TInstance, +): AnimatedComponentType< + $ReadOnly>, + React.ElementRef, +> { return unstable_createAnimatedComponentWithAllowlist(Component, null); } export function unstable_createAnimatedComponentWithAllowlist< TProps: {...}, - TInstance, + TInstance: React.ComponentType, >( - Component: component(ref: React.RefSetter, ...TProps), + Component: TInstance, allowlist: ?AnimatedPropsAllowlist, -): StrictAnimatedComponentType { +): StrictAnimatedComponentType> { const useAnimatedProps = createAnimatedPropsHook(allowlist); - const AnimatedComponent = React.forwardRef< + const AnimatedComponent: StrictAnimatedComponentType< + TProps, + React.ElementRef, + > = React.forwardRef< StrictAnimatedProps, - TInstance, + React.ElementRef, >((props, forwardedRef) => { - const [reducedProps, callbackRef] = useAnimatedProps( - props, + const [reducedProps, callbackRef] = useAnimatedProps< + TProps, + React.ElementRef, + >(props); + const ref = useMergeRefs>( + callbackRef, + forwardedRef, ); - const ref = useMergeRefs(callbackRef, forwardedRef); // Some components require explicit passthrough values for animation // to work properly. For example, if an animated component is 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 8808755bebf0..c63d72e01b66 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 @@ -648,24 +648,26 @@ export type StrictAnimatedProps = $ReadOnly<{ export type AnimatedComponentType< Props: { ... }, +Instance = mixed, -> = component(ref: React.RefSetter, ...AnimatedProps); +> = component(ref?: React.RefSetter, ...AnimatedProps); export type StrictAnimatedComponentType< Props: { ... }, +Instance = mixed, > = component(ref: React.RefSetter, ...StrictAnimatedProps); declare export default function createAnimatedComponent< - TProps: { ... }, - TInstance, + TInstance: React.ComponentType, >( - Component: component(ref: React.RefSetter, ...TProps) -): AnimatedComponentType; + Component: TInstance +): AnimatedComponentType< + $ReadOnly>, + React.ElementRef, +>; declare export function unstable_createAnimatedComponentWithAllowlist< TProps: { ... }, - TInstance, + TInstance: React.ComponentType, >( - Component: component(ref: React.RefSetter, ...TProps), + Component: TInstance, allowlist: ?AnimatedPropsAllowlist -): StrictAnimatedComponentType; +): StrictAnimatedComponentType>; " `;