diff --git a/packages/react-native/Libraries/Components/ScrollView/ScrollView.d.ts b/packages/react-native/Libraries/Components/ScrollView/ScrollView.d.ts index bd9f15396e75..775fe9466ae3 100644 --- a/packages/react-native/Libraries/Components/ScrollView/ScrollView.d.ts +++ b/packages/react-native/Libraries/Components/ScrollView/ScrollView.d.ts @@ -836,10 +836,29 @@ export interface ScrollViewProps StickyHeaderComponent?: React.ComponentType | undefined; } -declare class ScrollViewComponent extends React.Component {} -export declare const ScrollViewBase: Constructor & - typeof ScrollViewComponent; -export class ScrollView extends ScrollViewBase { +export interface ScrollViewScrollToOptions { + x?: number; + y?: number; + animated?: boolean; +} + +// Public methods for ScrollView +export interface ScrollViewImperativeMethods { + /** + * Returns a reference to the underlying scroll responder, which supports + * operations like `scrollTo`. All ScrollView-like components should + * implement this method so that they can be composed while providing access + * to the underlying scroll responder's methods. + */ + readonly getScrollResponder: () => ScrollResponderType; + readonly getScrollableNode: () => number | undefined; + readonly getInnerViewNode: () => number | undefined; + readonly getInnerViewRef: () => React.ComponentRef | null; + /** + * Returns a reference to the underlying native scroll view, or null if the + * native instance is not mounted. + */ + readonly getNativeScrollRef: () => HostInstance | null; /** * Scrolls to a given x, y offset, either immediately or with a smooth animation. * Syntax: @@ -850,18 +869,11 @@ export class ScrollView extends ScrollViewBase { * the function also accepts separate arguments as an alternative to the options object. * This is deprecated due to ambiguity (y before x), and SHOULD NOT BE USED. */ - scrollTo( - y?: - | number - | { - x?: number | undefined; - y?: number | undefined; - animated?: boolean | undefined; - }, + readonly scrollTo: ( + options?: ScrollViewScrollToOptions | number, deprecatedX?: number, deprecatedAnimated?: boolean, - ): void; - + ) => void; /** * A helper function that scrolls to the end of the scrollview; * If this is a vertical ScrollView, it scrolls to the bottom. @@ -870,32 +882,39 @@ export class ScrollView extends ScrollViewBase { * The options object has an animated prop, that enables the scrolling animation or not. * The animated prop defaults to true */ - scrollToEnd(options?: {animated?: boolean | undefined}): void; - + readonly scrollToEnd: (options?: ScrollViewScrollToOptions | null) => void; /** * Displays the scroll indicators momentarily. */ - flashScrollIndicators(): void; - - /** - * Returns a reference to the underlying scroll responder, which supports - * operations like `scrollTo`. All ScrollView-like components should - * implement this method so that they can be composed while providing access - * to the underlying scroll responder's methods. - */ - getScrollResponder(): ScrollResponderMixin; - - getScrollableNode(): any; + readonly flashScrollIndicators: () => void; + readonly scrollResponderZoomTo: ( + rect: { + x: number; + y: number; + width: number; + height: number; + animated?: boolean; + }, + animated?: boolean, // deprecated, put this inside the rect argument instead + ) => void; + readonly scrollResponderScrollNativeHandleToKeyboard: ( + nodeHandle: number | HostInstance, + additionalOffset?: number, + preventNegativeScrollOffset?: boolean, + ) => void; +} - // Undocumented - getInnerViewNode(): any; +export type ScrollResponderType = ScrollViewImperativeMethods; - /** - * Returns a reference to the underlying native scroll view, or null if the - * native instance is not mounted. - */ - getNativeScrollRef: () => HostInstance | null; +export interface PublicScrollViewInstance + extends HostInstance, + ScrollViewImperativeMethods {} +declare class ScrollViewComponent extends React.Component {} +export declare const ScrollViewBase: Constructor & + typeof ScrollViewComponent; +export interface ScrollView extends ScrollViewImperativeMethods {} +export class ScrollView extends ScrollViewBase { /** * @deprecated Use scrollTo instead */ diff --git a/packages/react-native/Libraries/Lists/FlatList.d.ts b/packages/react-native/Libraries/Lists/FlatList.d.ts index 06c4bca1f528..a1a8aa4cb735 100644 --- a/packages/react-native/Libraries/Lists/FlatList.d.ts +++ b/packages/react-native/Libraries/Lists/FlatList.d.ts @@ -14,10 +14,9 @@ import type { VirtualizedListProps, ViewabilityConfig, } from '@react-native/virtualized-lists'; -import type {ScrollViewComponent} from '../Components/ScrollView/ScrollView'; +import type {PublicScrollViewInstance} from '../Components/ScrollView/ScrollView'; import type {StyleProp} from '../StyleSheet/StyleSheet'; import type {ViewStyle} from '../StyleSheet/StyleSheetTypes'; -import type {View} from '../Components/View/View'; export interface FlatListProps extends VirtualizedListProps { /** @@ -229,13 +228,10 @@ export abstract class FlatListComponent< getScrollResponder: () => React.JSX.Element | null | undefined; /** - * Provides a reference to the underlying host component + * Returns a reference to the underlying native scroll view, or null if the + * native instance is not mounted. */ - getNativeScrollRef: () => - | React.ComponentRef - | React.ComponentRef - | null - | undefined; + getNativeScrollRef: () => PublicScrollViewInstance | null; getScrollableNode: () => any; diff --git a/packages/react-native/Libraries/Lists/FlatList.js b/packages/react-native/Libraries/Lists/FlatList.js index e908863fb945..13ac6fe26d8c 100644 --- a/packages/react-native/Libraries/Lists/FlatList.js +++ b/packages/react-native/Libraries/Lists/FlatList.js @@ -8,7 +8,6 @@ * @format */ -import typeof ScrollViewNativeComponent from '../Components/ScrollView/ScrollViewNativeComponent'; import type {ViewStyleProp} from '../StyleSheet/StyleSheet'; import type { ListRenderItem, @@ -19,7 +18,10 @@ import type { } from '@react-native/virtualized-lists'; import * as ReactNativeFeatureFlags from '../../src/private/featureflags/ReactNativeFeatureFlags'; -import {type ScrollResponderType} from '../Components/ScrollView/ScrollView'; +import { + type PublicScrollViewInstance, + type ScrollResponderType, +} from '../Components/ScrollView/ScrollView'; import View from '../Components/View/View'; import VirtualizedLists from '@react-native/virtualized-lists'; import memoizeOne from 'memoize-one'; @@ -395,14 +397,10 @@ class FlatList extends React.PureComponent> { } /** - * Provides a reference to the underlying host component + * Returns a reference to the underlying native scroll view. */ - getNativeScrollRef(): - | ?React.ElementRef - | ?React.ElementRef { + getNativeScrollRef(): ?PublicScrollViewInstance { if (this._listRef) { - /* $FlowFixMe[incompatible-return] Suppresses errors found when fixing - * TextInput typing */ return this._listRef.getScrollRef(); } }