Make use of ref-as-prop support in ScrollView (#51365)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51365

Make use of the React 19 feature so that we can remove the remaining `forwardRef` in react native.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D74814123

fbshipit-source-id: 5f9410df1710f6a9c59fea7ce1f225b04b67d664
This commit is contained in:
Sam Zhou
2025-05-15 13:59:31 -07:00
committed by Facebook GitHub Bot
parent 22a55dc9b9
commit ba86a8f863
@@ -1910,23 +1910,25 @@ function createRefForwarder<TNativeInstance, TPublicInstance>(
return state;
}
// TODO: After upgrading to React 19, remove `forwardRef` from this component.
// NOTE: This wrapper component is necessary because `ScrollView` is a class
// component and we need to map `ref` to a differently named prop. This can be
// removed when `ScrollView` is a functional component.
const ScrollViewWrapper: component(
ref?: React.RefSetter<PublicScrollViewInstance>,
...props: ScrollViewProps
) = React.forwardRef(function Wrapper(
props: ScrollViewProps,
ref: ?React.RefSetter<PublicScrollViewInstance>,
): React.Node {
) = function Wrapper({
ref,
...props
}: {
ref?: React.RefSetter<PublicScrollViewInstance>,
...ScrollViewProps,
}): React.Node {
return ref == null ? (
<ScrollView {...props} />
) : (
<ScrollView {...props} scrollViewRef={ref} />
);
});
};
ScrollViewWrapper.displayName = 'ScrollView';
// $FlowExpectedError[prop-missing]
ScrollViewWrapper.Context = ScrollViewContext;