diff --git a/packages/react-native/Libraries/Components/ScrollView/ScrollView.js b/packages/react-native/Libraries/Components/ScrollView/ScrollView.js index d770cbbe3fc..fc330dfd5c5 100644 --- a/packages/react-native/Libraries/Components/ScrollView/ScrollView.js +++ b/packages/react-native/Libraries/Components/ScrollView/ScrollView.js @@ -649,13 +649,13 @@ export type Props = $ReadOnly<{| * A ref to the inner View element of the ScrollView. This should be used * instead of calling `getInnerViewRef`. */ - innerViewRef?: ForwardedRef, + innerViewRef?: React.RefSetter, /** * A ref to the Native ScrollView component. This ref can be used to call * all of ScrollView's public methods, in addition to native methods like * measure, measureLayout, etc. */ - scrollViewRef?: ForwardedRef, + scrollViewRef?: React.RefSetter, |}>; type State = {| @@ -1891,11 +1891,9 @@ const styles = StyleSheet.create({ }, }); -type ForwardedRef = {current: null | T, ...} | ((null | T) => mixed); - type RefForwarder = { getForwardingRef: ( - ?ForwardedRef, + ?React.RefSetter, ) => (TNativeInstance | null) => void, nativeInstance: TNativeInstance | null, publicInstance: TPublicInstance | null, @@ -1933,21 +1931,22 @@ function createRefForwarder( return state; } -/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's - * LTI update could not be added via codemod */ -function Wrapper(props, ref: (mixed => mixed) | {current: mixed, ...}) { +// 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. +function Wrapper({ + ref, + ...props +}: { + ...Props, + ref: React.RefSetter, +}): React.Node { return ; } Wrapper.displayName = 'ScrollView'; -// $FlowFixMe[incompatible-call] -const ForwardedScrollView = React.forwardRef(Wrapper); +Wrapper.Context = ScrollViewContext; -// $FlowFixMe[prop-missing] Add static context to ForwardedScrollView -ForwardedScrollView.Context = ScrollViewContext; - -ForwardedScrollView.displayName = 'ScrollView'; - -module.exports = ((ForwardedScrollView: $FlowFixMe): React.AbstractComponent< +module.exports = ((Wrapper: $FlowFixMe): React.AbstractComponent< React.ElementConfig, PublicScrollViewInstance, > & diff --git a/packages/react-native/Libraries/Components/ScrollView/__tests__/__snapshots__/ScrollView-test.js.snap b/packages/react-native/Libraries/Components/ScrollView/__tests__/__snapshots__/ScrollView-test.js.snap index a605fe25bf7..44636eb9dab 100644 --- a/packages/react-native/Libraries/Components/ScrollView/__tests__/__snapshots__/ScrollView-test.js.snap +++ b/packages/react-native/Libraries/Components/ScrollView/__tests__/__snapshots__/ScrollView-test.js.snap @@ -34,7 +34,6 @@ exports[`ScrollView renders its children: should deep render when not mocked (pl onTouchMove={[Function]} onTouchStart={[Function]} pagingEnabled={false} - scrollViewRef={null} sendMomentumEvents={false} snapToEnd={true} snapToStart={true}