1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | import type * as React from 'react';
|
11 | import type {
|
12 | ListRenderItem,
|
13 | ViewToken,
|
14 | VirtualizedListProps,
|
15 | ViewabilityConfig,
|
16 | } from '@react-native/virtualized-lists';
|
17 | import type {ScrollViewComponent} from '../Components/ScrollView/ScrollView';
|
18 | import type {StyleProp} from '../StyleSheet/StyleSheet';
|
19 | import type {ViewStyle} from '../StyleSheet/StyleSheetTypes';
|
20 | import type {View} from '../Components/View/View';
|
21 |
|
22 | export interface FlatListProps<ItemT> extends VirtualizedListProps<ItemT> {
|
23 | |
24 |
|
25 |
|
26 | columnWrapperStyle?: StyleProp<ViewStyle> | undefined;
|
27 |
|
28 | |
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | keyboardShouldPersistTaps?:
|
37 | | boolean
|
38 | | 'always'
|
39 | | 'never'
|
40 | | 'handled'
|
41 | | undefined;
|
42 |
|
43 | |
44 |
|
45 |
|
46 |
|
47 | data: ArrayLike<ItemT> | null | undefined;
|
48 |
|
49 | |
50 |
|
51 |
|
52 |
|
53 |
|
54 | extraData?: any | undefined;
|
55 |
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | getItemLayout?:
|
69 | | ((
|
70 | data: ArrayLike<ItemT> | null | undefined,
|
71 | index: number,
|
72 | ) => {length: number; offset: number; index: number})
|
73 | | undefined;
|
74 |
|
75 | |
76 |
|
77 |
|
78 | horizontal?: boolean | null | undefined;
|
79 |
|
80 | |
81 |
|
82 |
|
83 | initialNumToRender?: number | undefined;
|
84 |
|
85 | |
86 |
|
87 |
|
88 | initialScrollIndex?: number | null | undefined;
|
89 |
|
90 | |
91 |
|
92 |
|
93 |
|
94 |
|
95 | keyExtractor?: ((item: ItemT, index: number) => string) | undefined;
|
96 |
|
97 | /**
|
98 | * Uses legacy MetroListView instead of default VirtualizedSectionList
|
99 | */
|
100 | legacyImplementation?: boolean | undefined;
|
101 |
|
102 | /**
|
103 | * Multiple columns can only be rendered with `horizontal={false}` and will zig-zag like a `flexWrap` layout.
|
104 | * Items should all be the same height - masonry layouts are not supported.
|
105 | */
|
106 | numColumns?: number | undefined;
|
107 |
|
108 | /**
|
109 | * If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality.
|
110 | * Make sure to also set the refreshing prop correctly.
|
111 | */
|
112 | onRefresh?: (() => void) | null | undefined;
|
113 |
|
114 | /**
|
115 | * Called when the viewability of rows changes, as defined by the `viewablePercentThreshold` prop.
|
116 | */
|
117 | onViewableItemsChanged?:
|
118 | | ((info: {
|
119 | viewableItems: Array<ViewToken<ItemT>>;
|
120 | changed: Array<ViewToken<ItemT>>;
|
121 | }) => void)
|
122 | | null
|
123 | | undefined;
|
124 |
|
125 | /**
|
126 | * Set this true while waiting for new data from a refresh.
|
127 | */
|
128 | refreshing?: boolean | null | undefined;
|
129 |
|
130 | /**
|
131 | * Takes an item from data and renders it into the list. Typical usage:
|
132 | * ```
|
133 | * _renderItem = ({item}) => (
|
134 | * <TouchableOpacity onPress={() => this._onPress(item)}>
|
135 | * <Text>{item.title}</Text>
|
136 | * </TouchableOpacity>
|
137 | * );
|
138 | * ...
|
139 | * <FlatList data={[{title: 'Title Text', key: 'item1'}]} renderItem={this._renderItem} />
|
140 | * ```
|
141 | * Provides additional metadata like `index` if you need it.
|
142 | */
|
143 | renderItem: ListRenderItem<ItemT> | null | undefined;
|
144 |
|
145 | /**
|
146 | * See `ViewabilityHelper` for flow type and further documentation.
|
147 | */
|
148 | viewabilityConfig?: ViewabilityConfig | undefined;
|
149 |
|
150 | /**
|
151 | * Note: may have bugs (missing content) in some circumstances - use at your own risk.
|
152 | *
|
153 | * This may improve scroll performance for large lists.
|
154 | */
|
155 | removeClippedSubviews?: boolean | undefined;
|
156 |
|
157 | /**
|
158 | * Fades out the edges of the scroll content.
|
159 | *
|
160 | * If the value is greater than 0, the fading edges will be set accordingly
|
161 | * to the current scroll direction and position,
|
162 | * indicating if there is more content to show.
|
163 | *
|
164 | * The default value is 0.
|
165 | * @platform android
|
166 | */
|
167 | fadingEdgeLength?: number | undefined;
|
168 | }
|
169 |
|
170 | export abstract class FlatListComponent<
|
171 | ItemT,
|
172 | Props,
|
173 | > extends React.Component<Props> {
|
174 | /**
|
175 | * Scrolls to the end of the content. May be janky without `getItemLayout` prop.
|
176 | */
|
177 | scrollToEnd: (params?: {animated?: boolean | null | undefined}) => void;
|
178 |
|
179 | /**
|
180 | * Scrolls to the item at the specified index such that it is positioned in the viewable area
|
181 | * such that viewPosition 0 places it at the top, 1 at the bottom, and 0.5 centered in the middle.
|
182 | * Cannot scroll to locations outside the render window without specifying the getItemLayout prop.
|
183 | */
|
184 | scrollToIndex: (params: {
|
185 | animated?: boolean | null | undefined;
|
186 | index: number;
|
187 | viewOffset?: number | undefined;
|
188 | viewPosition?: number | undefined;
|
189 | }) => void;
|
190 |
|
191 | /**
|
192 | * Requires linear scan through data - use `scrollToIndex` instead if possible.
|
193 | * May be janky without `getItemLayout` prop.
|
194 | */
|
195 | scrollToItem: (params: {
|
196 | animated?: boolean | null | undefined;
|
197 | item: ItemT;
|
198 | viewOffset?: number | undefined;
|
199 | viewPosition?: number | undefined;
|
200 | }) => void;
|
201 |
|
202 | /**
|
203 | * Scroll to a specific content pixel offset, like a normal `ScrollView`.
|
204 | */
|
205 | scrollToOffset: (params: {
|
206 | animated?: boolean | null | undefined;
|
207 | offset: number;
|
208 | }) => void;
|
209 |
|
210 | /**
|
211 | * Tells the list an interaction has occurred, which should trigger viewability calculations,
|
212 | * e.g. if waitForInteractions is true and the user has not scrolled. This is typically called
|
213 | * by taps on items or by navigation actions.
|
214 | */
|
215 | recordInteraction: () => void;
|
216 |
|
217 | /**
|
218 | * Displays the scroll indicators momentarily.
|
219 | */
|
220 | flashScrollIndicators: () => void;
|
221 |
|
222 | /**
|
223 | * Provides a handle to the underlying scroll responder.
|
224 | */
|
225 | getScrollResponder: () => JSX.Element | null | undefined;
|
226 |
|
227 | /**
|
228 | * Provides a reference to the underlying host component
|
229 | */
|
230 | getNativeScrollRef: () =>
|
231 | | React.ElementRef<typeof View>
|
232 | | React.ElementRef<typeof ScrollViewComponent>
|
233 | | null
|
234 | | undefined;
|
235 |
|
236 | getScrollableNode: () => any;
|
237 |
|
238 | // TODO: use `unknown` instead of `any` for Typescript >= 3.0
|
239 | setNativeProps: (props: {[key: string]: any}) => void;
|
240 | }
|
241 |
|
242 | export class FlatList<ItemT = any> extends FlatListComponent<
|
243 | ItemT,
|
244 | FlatListProps<ItemT>
|
245 | > {}
|
246 |
|
\ | No newline at end of file |