From 1be2ba4597fbe835ec461caa9dd838e4186b49eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ma=C5=82ecki?= Date: Wed, 22 Jan 2025 10:00:50 -0800 Subject: [PATCH] Replace $FlowFixMe in ScrollView (#48857) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48857 Changelog: [General][Changed] - Improved types in ScrollView Reviewed By: huntie Differential Revision: D68496037 fbshipit-source-id: b044e884fb78bb92c0da5acd7570a87ff328a479 --- .../Components/ScrollView/ScrollView.js | 16 +++++++++++----- .../__snapshots__/public-api-test.js.snap | 15 +++++++++------ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/react-native/Libraries/Components/ScrollView/ScrollView.js b/packages/react-native/Libraries/Components/ScrollView/ScrollView.js index 5c0fe1bc053..d4c973dcd69 100644 --- a/packages/react-native/Libraries/Components/ScrollView/ScrollView.js +++ b/packages/react-native/Libraries/Components/ScrollView/ScrollView.js @@ -712,9 +712,11 @@ class ScrollView extends React.Component { _scrollAnimatedValue: AnimatedImplementation.Value; _scrollAnimatedValueAttachment: ?{detach: () => void, ...} = null; - _stickyHeaderRefs: Map> = - new Map(); - _headerLayoutYs: Map = new Map(); + _stickyHeaderRefs: Map< + React.Key, + React.ElementRef, + > = new Map(); + _headerLayoutYs: Map = new Map(); _keyboardMetrics: ?KeyboardMetrics = null; _additionalScrollOffset: number = 0; @@ -1066,7 +1068,11 @@ class ScrollView extends React.Component { } }; - _getKeyForIndex(index: $FlowFixMe, childArray: $FlowFixMe): $FlowFixMe { + _getKeyForIndex( + index: number, + // $FlowFixMe[unclear-type] - The children and its key is unknown. + childArray: any, + ): React.Key { const child = childArray[index]; return child && child.key; } @@ -1099,7 +1105,7 @@ class ScrollView extends React.Component { } } - _onStickyHeaderLayout(index: $FlowFixMe, event: $FlowFixMe, key: $FlowFixMe) { + _onStickyHeaderLayout(index: number, event: LayoutEvent, key: React.Key) { const {stickyHeaderIndices} = this.props; if (!stickyHeaderIndices) { return; 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 23cab6685c4..8c0226c46b2 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 @@ -2154,8 +2154,11 @@ declare class ScrollView extends React.Component { constructor(props: Props): void; _scrollAnimatedValue: AnimatedImplementation.Value; _scrollAnimatedValueAttachment: ?{ detach: () => void, ... }; - _stickyHeaderRefs: Map>; - _headerLayoutYs: Map; + _stickyHeaderRefs: Map< + React.Key, + React.ElementRef, + >; + _headerLayoutYs: Map; _keyboardMetrics: ?KeyboardMetrics; _additionalScrollOffset: number; _isTouching: boolean; @@ -2214,16 +2217,16 @@ declare class ScrollView extends React.Component { width: number, height: number ) => void; - _getKeyForIndex(index: $FlowFixMe, childArray: $FlowFixMe): $FlowFixMe; + _getKeyForIndex(index: number, childArray: any): React.Key; _updateAnimatedNodeAttachment(): void; _setStickyHeaderRef( key: string, ref: ?React.ElementRef ): void; _onStickyHeaderLayout( - index: $FlowFixMe, - event: $FlowFixMe, - key: $FlowFixMe + index: number, + event: LayoutEvent, + key: React.Key ): void; _handleScroll: $FlowFixMe; _handleLayout: $FlowFixMe;