From 621969b8d85d10f4f9b66be7d5deae58651dc6aa Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 15 Dec 2022 12:41:38 -0800 Subject: [PATCH] Add missing VirtualizedList Imperative Types Summary: Adds some imperative VirtualizedList methods to the TS types which are documented on the website and are public enough. Also explicitly add `viewOffset` to `scrollToItem` since `scrollToItem` params are indefinite in flow and are passed to `scrollToIndex` (which supports the prop). Changelog: [General][Fixed] - Add missing VirtualizedList Imperative Types Reviewed By: GijsWeterings Differential Revision: D42047674 fbshipit-source-id: 60f7b35b049853d9fcb724918b3a0008a75ea573 --- Libraries/Lists/FlatList.d.ts | 1 + Libraries/Lists/FlatList.js | 1 + Libraries/Lists/VirtualizedList.d.ts | 15 ++++++++++++++- Libraries/Lists/VirtualizedList.js | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Libraries/Lists/FlatList.d.ts b/Libraries/Lists/FlatList.d.ts index 331c161e0dc99b..9796869d3dbce7 100644 --- a/Libraries/Lists/FlatList.d.ts +++ b/Libraries/Lists/FlatList.d.ts @@ -206,6 +206,7 @@ export class FlatList extends React.Component< scrollToItem: (params: { animated?: boolean | null | undefined; item: ItemT; + viewOffset?: number | undefined; viewPosition?: number | undefined; }) => void; diff --git a/Libraries/Lists/FlatList.js b/Libraries/Lists/FlatList.js index 3da7714a670b29..56748eaf75240d 100644 --- a/Libraries/Lists/FlatList.js +++ b/Libraries/Lists/FlatList.js @@ -334,6 +334,7 @@ class FlatList extends React.PureComponent, void> { scrollToItem(params: { animated?: ?boolean, item: ItemT, + viewOffset?: number, viewPosition?: number, ... }) { diff --git a/Libraries/Lists/VirtualizedList.d.ts b/Libraries/Lists/VirtualizedList.d.ts index 3a4bbfe0c0c9a7..eaef385999f51d 100644 --- a/Libraries/Lists/VirtualizedList.d.ts +++ b/Libraries/Lists/VirtualizedList.d.ts @@ -11,7 +11,12 @@ import type * as React from 'react'; import type {LayoutChangeEvent} from '../../types'; import {StyleProp} from '../StyleSheet/StyleSheet'; import {ViewStyle} from '../StyleSheet/StyleSheetTypes'; -import type {ScrollViewProps} from '../Components/ScrollView/ScrollView'; +import type { + ScrollResponderMixin, + ScrollView, + ScrollViewProps, +} from '../Components/ScrollView/ScrollView'; +import type {View} from '../Components/View/View'; export interface ViewToken { item: any; @@ -98,6 +103,7 @@ export class VirtualizedList extends React.Component< scrollToItem: (params: { animated?: boolean | undefined; item: ItemT; + viewOffset?: number | undefined; viewPosition?: number | undefined; }) => void; @@ -113,6 +119,13 @@ export class VirtualizedList extends React.Component< }) => void; recordInteraction: () => void; + + getScrollRef: () => + | React.ElementRef + | React.ElementRef + | null; + + getScrollResponder: () => ScrollResponderMixin | null; } /** diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index cf11abbfaf4138..a6114ccaf0015c 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -263,6 +263,7 @@ export default class VirtualizedList extends StateSafePureComponent< scrollToItem(params: { animated?: ?boolean, item: Item, + viewOffset?: number, viewPosition?: number, ... }) {