Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -836,10 +836,29 @@ export interface ScrollViewProps
StickyHeaderComponent?: React.ComponentType<any> | undefined;
}

declare class ScrollViewComponent extends React.Component<ScrollViewProps> {}
export declare const ScrollViewBase: Constructor<ScrollResponderMixin> &
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<typeof View> | 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:
Expand All @@ -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.
Expand All @@ -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<ScrollViewProps> {}
export declare const ScrollViewBase: Constructor<ScrollResponderMixin> &
typeof ScrollViewComponent;
export interface ScrollView extends ScrollViewImperativeMethods {}
export class ScrollView extends ScrollViewBase {
/**
* @deprecated Use scrollTo instead
*/
Expand Down
12 changes: 4 additions & 8 deletions packages/react-native/Libraries/Lists/FlatList.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemT> extends VirtualizedListProps<ItemT> {
/**
Expand Down Expand Up @@ -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<typeof View>
| React.ComponentRef<typeof ScrollViewComponent>
| null
| undefined;
getNativeScrollRef: () => PublicScrollViewInstance | null;

getScrollableNode: () => any;

Expand Down
14 changes: 6 additions & 8 deletions packages/react-native/Libraries/Lists/FlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* @format
*/

import typeof ScrollViewNativeComponent from '../Components/ScrollView/ScrollViewNativeComponent';
import type {ViewStyleProp} from '../StyleSheet/StyleSheet';
import type {
ListRenderItem,
Expand All @@ -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 {
Copy link
Copy Markdown
Member

@huntie huntie May 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I ask that we omit changes outside the .d.ts files in this PR? I'm actioning these in #56718 🙂

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';
Expand Down Expand Up @@ -395,14 +397,10 @@ class FlatList<ItemT = any> extends React.PureComponent<FlatListProps<ItemT>> {
}

/**
* Provides a reference to the underlying host component
* Returns a reference to the underlying native scroll view.
*/
getNativeScrollRef():
| ?React.ElementRef<typeof View>
| ?React.ElementRef<ScrollViewNativeComponent> {
getNativeScrollRef(): ?PublicScrollViewInstance {
if (this._listRef) {
/* $FlowFixMe[incompatible-return] Suppresses errors found when fixing
* TextInput typing */
return this._listRef.getScrollRef();
}
}
Expand Down
Loading