@react-native-tvos/virtualized-lists 0.73.4-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Interaction/Batchinator.js +76 -0
- package/Lists/CellRenderMask.js +155 -0
- package/Lists/ChildListCollection.js +72 -0
- package/Lists/FillRateHelper.js +245 -0
- package/Lists/ListMetricsAggregator.js +303 -0
- package/Lists/StateSafePureComponent.js +85 -0
- package/Lists/ViewabilityHelper.js +348 -0
- package/Lists/VirtualizeUtils.js +245 -0
- package/Lists/VirtualizedList.d.ts +393 -0
- package/Lists/VirtualizedList.js +2019 -0
- package/Lists/VirtualizedListCellRenderer.js +245 -0
- package/Lists/VirtualizedListContext.js +114 -0
- package/Lists/VirtualizedListProps.js +337 -0
- package/Lists/VirtualizedSectionList.js +617 -0
- package/README.md +23 -0
- package/Utilities/clamp.js +23 -0
- package/Utilities/infoLog.js +20 -0
- package/index.d.ts +10 -0
- package/index.js +58 -0
- package/package.json +32 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet';
|
|
12
|
+
import type {
|
|
13
|
+
FocusEvent,
|
|
14
|
+
LayoutEvent,
|
|
15
|
+
} from 'react-native/Libraries/Types/CoreEventTypes';
|
|
16
|
+
import type {CellRendererProps, RenderItemType} from './VirtualizedListProps';
|
|
17
|
+
|
|
18
|
+
import {View, StyleSheet} from 'react-native';
|
|
19
|
+
import {VirtualizedListCellContextProvider} from './VirtualizedListContext.js';
|
|
20
|
+
import invariant from 'invariant';
|
|
21
|
+
import * as React from 'react';
|
|
22
|
+
|
|
23
|
+
export type Props<ItemT> = {
|
|
24
|
+
CellRendererComponent?: ?React.ComponentType<CellRendererProps<ItemT>>,
|
|
25
|
+
ItemSeparatorComponent: ?React.ComponentType<
|
|
26
|
+
any | {highlighted: boolean, leadingItem: ?ItemT},
|
|
27
|
+
>,
|
|
28
|
+
ListItemComponent?: ?(React.ComponentType<any> | React.Element<any>),
|
|
29
|
+
cellKey: string,
|
|
30
|
+
horizontal: ?boolean,
|
|
31
|
+
index: number,
|
|
32
|
+
inversionStyle: ViewStyleProp,
|
|
33
|
+
item: ItemT,
|
|
34
|
+
onCellLayout?: (event: LayoutEvent, cellKey: string, index: number) => void,
|
|
35
|
+
onCellFocusCapture?: (event: FocusEvent) => void,
|
|
36
|
+
onUnmount: (cellKey: string) => void,
|
|
37
|
+
onUpdateSeparators: (
|
|
38
|
+
cellKeys: Array<?string>,
|
|
39
|
+
props: Partial<SeparatorProps<ItemT>>,
|
|
40
|
+
) => void,
|
|
41
|
+
prevCellKey: ?string,
|
|
42
|
+
renderItem?: ?RenderItemType<ItemT>,
|
|
43
|
+
...
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
type SeparatorProps<ItemT> = $ReadOnly<{|
|
|
47
|
+
highlighted: boolean,
|
|
48
|
+
leadingItem: ?ItemT,
|
|
49
|
+
|}>;
|
|
50
|
+
|
|
51
|
+
type State<ItemT> = {
|
|
52
|
+
separatorProps: SeparatorProps<ItemT>,
|
|
53
|
+
...
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default class CellRenderer<ItemT> extends React.Component<
|
|
57
|
+
Props<ItemT>,
|
|
58
|
+
State<ItemT>,
|
|
59
|
+
> {
|
|
60
|
+
state: State<ItemT> = {
|
|
61
|
+
separatorProps: {
|
|
62
|
+
highlighted: false,
|
|
63
|
+
leadingItem: this.props.item,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
static getDerivedStateFromProps(
|
|
68
|
+
props: Props<ItemT>,
|
|
69
|
+
prevState: State<ItemT>,
|
|
70
|
+
): ?State<ItemT> {
|
|
71
|
+
return {
|
|
72
|
+
separatorProps: {
|
|
73
|
+
...prevState.separatorProps,
|
|
74
|
+
leadingItem: props.item,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// TODO: consider factoring separator stuff out of VirtualizedList into FlatList since it's not
|
|
80
|
+
// reused by SectionList and we can keep VirtualizedList simpler.
|
|
81
|
+
// $FlowFixMe[missing-local-annot]
|
|
82
|
+
_separators = {
|
|
83
|
+
highlight: () => {
|
|
84
|
+
const {cellKey, prevCellKey} = this.props;
|
|
85
|
+
this.props.onUpdateSeparators([cellKey, prevCellKey], {
|
|
86
|
+
highlighted: true,
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
unhighlight: () => {
|
|
90
|
+
const {cellKey, prevCellKey} = this.props;
|
|
91
|
+
this.props.onUpdateSeparators([cellKey, prevCellKey], {
|
|
92
|
+
highlighted: false,
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
updateProps: (
|
|
96
|
+
select: 'leading' | 'trailing',
|
|
97
|
+
newProps: SeparatorProps<ItemT>,
|
|
98
|
+
) => {
|
|
99
|
+
const {cellKey, prevCellKey} = this.props;
|
|
100
|
+
this.props.onUpdateSeparators(
|
|
101
|
+
[select === 'leading' ? prevCellKey : cellKey],
|
|
102
|
+
newProps,
|
|
103
|
+
);
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
updateSeparatorProps(newProps: SeparatorProps<ItemT>) {
|
|
108
|
+
this.setState(state => ({
|
|
109
|
+
separatorProps: {...state.separatorProps, ...newProps},
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
componentWillUnmount() {
|
|
114
|
+
this.props.onUnmount(this.props.cellKey);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
_onLayout = (nativeEvent: LayoutEvent): void => {
|
|
118
|
+
this.props.onCellLayout &&
|
|
119
|
+
this.props.onCellLayout(
|
|
120
|
+
nativeEvent,
|
|
121
|
+
this.props.cellKey,
|
|
122
|
+
this.props.index,
|
|
123
|
+
);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
_renderElement(
|
|
127
|
+
renderItem: ?RenderItemType<ItemT>,
|
|
128
|
+
ListItemComponent: any,
|
|
129
|
+
item: ItemT,
|
|
130
|
+
index: number,
|
|
131
|
+
): React.Node {
|
|
132
|
+
if (renderItem && ListItemComponent) {
|
|
133
|
+
console.warn(
|
|
134
|
+
'VirtualizedList: Both ListItemComponent and renderItem props are present. ListItemComponent will take' +
|
|
135
|
+
' precedence over renderItem.',
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (ListItemComponent) {
|
|
140
|
+
/* $FlowFixMe[not-a-component] (>=0.108.0 site=react_native_fb) This
|
|
141
|
+
* comment suppresses an error found when Flow v0.108 was deployed. To
|
|
142
|
+
* see the error, delete this comment and run Flow. */
|
|
143
|
+
/* $FlowFixMe[incompatible-type-arg] (>=0.108.0 site=react_native_fb)
|
|
144
|
+
* This comment suppresses an error found when Flow v0.108 was deployed.
|
|
145
|
+
* To see the error, delete this comment and run Flow. */
|
|
146
|
+
return React.createElement(ListItemComponent, {
|
|
147
|
+
item,
|
|
148
|
+
index,
|
|
149
|
+
separators: this._separators,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (renderItem) {
|
|
154
|
+
return renderItem({
|
|
155
|
+
item,
|
|
156
|
+
index,
|
|
157
|
+
separators: this._separators,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
invariant(
|
|
162
|
+
false,
|
|
163
|
+
'VirtualizedList: Either ListItemComponent or renderItem props are required but none were found.',
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
render(): React.Node {
|
|
168
|
+
const {
|
|
169
|
+
CellRendererComponent,
|
|
170
|
+
ItemSeparatorComponent,
|
|
171
|
+
ListItemComponent,
|
|
172
|
+
cellKey,
|
|
173
|
+
horizontal,
|
|
174
|
+
item,
|
|
175
|
+
index,
|
|
176
|
+
inversionStyle,
|
|
177
|
+
onCellFocusCapture,
|
|
178
|
+
onCellLayout,
|
|
179
|
+
renderItem,
|
|
180
|
+
} = this.props;
|
|
181
|
+
const element = this._renderElement(
|
|
182
|
+
renderItem,
|
|
183
|
+
ListItemComponent,
|
|
184
|
+
item,
|
|
185
|
+
index,
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
// NOTE: that when this is a sticky header, `onLayout` will get automatically extracted and
|
|
189
|
+
// called explicitly by `ScrollViewStickyHeader`.
|
|
190
|
+
const itemSeparator: React.Node = React.isValidElement(
|
|
191
|
+
ItemSeparatorComponent,
|
|
192
|
+
)
|
|
193
|
+
? // $FlowFixMe[incompatible-type]
|
|
194
|
+
ItemSeparatorComponent
|
|
195
|
+
: // $FlowFixMe[incompatible-type]
|
|
196
|
+
ItemSeparatorComponent && (
|
|
197
|
+
<ItemSeparatorComponent {...this.state.separatorProps} />
|
|
198
|
+
);
|
|
199
|
+
const cellStyle = inversionStyle
|
|
200
|
+
? horizontal
|
|
201
|
+
? [styles.rowReverse, inversionStyle]
|
|
202
|
+
: [styles.columnReverse, inversionStyle]
|
|
203
|
+
: horizontal
|
|
204
|
+
? [styles.row, inversionStyle]
|
|
205
|
+
: inversionStyle;
|
|
206
|
+
const result = !CellRendererComponent ? (
|
|
207
|
+
<View
|
|
208
|
+
style={cellStyle}
|
|
209
|
+
onFocusCapture={onCellFocusCapture}
|
|
210
|
+
{...(onCellLayout && {onLayout: this._onLayout})}>
|
|
211
|
+
{element}
|
|
212
|
+
{itemSeparator}
|
|
213
|
+
</View>
|
|
214
|
+
) : (
|
|
215
|
+
<CellRendererComponent
|
|
216
|
+
cellKey={cellKey}
|
|
217
|
+
index={index}
|
|
218
|
+
item={item}
|
|
219
|
+
style={cellStyle}
|
|
220
|
+
onFocusCapture={onCellFocusCapture}
|
|
221
|
+
{...(onCellLayout && {onLayout: this._onLayout})}>
|
|
222
|
+
{element}
|
|
223
|
+
{itemSeparator}
|
|
224
|
+
</CellRendererComponent>
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
return (
|
|
228
|
+
<VirtualizedListCellContextProvider cellKey={this.props.cellKey}>
|
|
229
|
+
{result}
|
|
230
|
+
</VirtualizedListCellContextProvider>
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const styles = StyleSheet.create({
|
|
236
|
+
row: {
|
|
237
|
+
flexDirection: 'row',
|
|
238
|
+
},
|
|
239
|
+
rowReverse: {
|
|
240
|
+
flexDirection: 'row-reverse',
|
|
241
|
+
},
|
|
242
|
+
columnReverse: {
|
|
243
|
+
flexDirection: 'column-reverse',
|
|
244
|
+
},
|
|
245
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import typeof VirtualizedList from './VirtualizedList';
|
|
12
|
+
|
|
13
|
+
import * as React from 'react';
|
|
14
|
+
import {useContext, useMemo} from 'react';
|
|
15
|
+
|
|
16
|
+
type Context = $ReadOnly<{
|
|
17
|
+
cellKey: ?string,
|
|
18
|
+
getScrollMetrics: () => {
|
|
19
|
+
contentLength: number,
|
|
20
|
+
dOffset: number,
|
|
21
|
+
dt: number,
|
|
22
|
+
offset: number,
|
|
23
|
+
timestamp: number,
|
|
24
|
+
velocity: number,
|
|
25
|
+
visibleLength: number,
|
|
26
|
+
zoomScale: number,
|
|
27
|
+
},
|
|
28
|
+
horizontal: ?boolean,
|
|
29
|
+
getOutermostParentListRef: () => React.ElementRef<VirtualizedList>,
|
|
30
|
+
registerAsNestedChild: ({
|
|
31
|
+
cellKey: string,
|
|
32
|
+
ref: React.ElementRef<VirtualizedList>,
|
|
33
|
+
}) => void,
|
|
34
|
+
unregisterAsNestedChild: ({ref: React.ElementRef<VirtualizedList>}) => void,
|
|
35
|
+
}>;
|
|
36
|
+
|
|
37
|
+
export const VirtualizedListContext: React.Context<?Context> =
|
|
38
|
+
React.createContext(null);
|
|
39
|
+
if (__DEV__) {
|
|
40
|
+
VirtualizedListContext.displayName = 'VirtualizedListContext';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Resets the context. Intended for use by portal-like components (e.g. Modal).
|
|
45
|
+
*/
|
|
46
|
+
export function VirtualizedListContextResetter({
|
|
47
|
+
children,
|
|
48
|
+
}: {
|
|
49
|
+
children: React.Node,
|
|
50
|
+
}): React.Node {
|
|
51
|
+
return (
|
|
52
|
+
<VirtualizedListContext.Provider value={null}>
|
|
53
|
+
{children}
|
|
54
|
+
</VirtualizedListContext.Provider>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Sets the context with memoization. Intended to be used by `VirtualizedList`.
|
|
60
|
+
*/
|
|
61
|
+
export function VirtualizedListContextProvider({
|
|
62
|
+
children,
|
|
63
|
+
value,
|
|
64
|
+
}: {
|
|
65
|
+
children: React.Node,
|
|
66
|
+
value: Context,
|
|
67
|
+
}): React.Node {
|
|
68
|
+
// Avoid setting a newly created context object if the values are identical.
|
|
69
|
+
const context = useMemo(
|
|
70
|
+
() => ({
|
|
71
|
+
cellKey: null,
|
|
72
|
+
getScrollMetrics: value.getScrollMetrics,
|
|
73
|
+
horizontal: value.horizontal,
|
|
74
|
+
getOutermostParentListRef: value.getOutermostParentListRef,
|
|
75
|
+
registerAsNestedChild: value.registerAsNestedChild,
|
|
76
|
+
unregisterAsNestedChild: value.unregisterAsNestedChild,
|
|
77
|
+
}),
|
|
78
|
+
[
|
|
79
|
+
value.getScrollMetrics,
|
|
80
|
+
value.horizontal,
|
|
81
|
+
value.getOutermostParentListRef,
|
|
82
|
+
value.registerAsNestedChild,
|
|
83
|
+
value.unregisterAsNestedChild,
|
|
84
|
+
],
|
|
85
|
+
);
|
|
86
|
+
return (
|
|
87
|
+
<VirtualizedListContext.Provider value={context}>
|
|
88
|
+
{children}
|
|
89
|
+
</VirtualizedListContext.Provider>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Sets the `cellKey`. Intended to be used by `VirtualizedList` for each cell.
|
|
95
|
+
*/
|
|
96
|
+
export function VirtualizedListCellContextProvider({
|
|
97
|
+
cellKey,
|
|
98
|
+
children,
|
|
99
|
+
}: {
|
|
100
|
+
cellKey: string,
|
|
101
|
+
children: React.Node,
|
|
102
|
+
}): React.Node {
|
|
103
|
+
// Avoid setting a newly created context object if the values are identical.
|
|
104
|
+
const currContext = useContext(VirtualizedListContext);
|
|
105
|
+
const context = useMemo(
|
|
106
|
+
() => (currContext == null ? null : {...currContext, cellKey}),
|
|
107
|
+
[currContext, cellKey],
|
|
108
|
+
);
|
|
109
|
+
return (
|
|
110
|
+
<VirtualizedListContext.Provider value={context}>
|
|
111
|
+
{children}
|
|
112
|
+
</VirtualizedListContext.Provider>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {typeof ScrollView} from 'react-native';
|
|
12
|
+
import type {
|
|
13
|
+
FocusEvent,
|
|
14
|
+
LayoutEvent,
|
|
15
|
+
} from 'react-native/Libraries/Types/CoreEventTypes';
|
|
16
|
+
import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet';
|
|
17
|
+
import type {
|
|
18
|
+
ViewabilityConfig,
|
|
19
|
+
ViewabilityConfigCallbackPair,
|
|
20
|
+
ViewToken,
|
|
21
|
+
} from './ViewabilityHelper';
|
|
22
|
+
|
|
23
|
+
import * as React from 'react';
|
|
24
|
+
|
|
25
|
+
export type Item = any;
|
|
26
|
+
|
|
27
|
+
export type Separators = {
|
|
28
|
+
highlight: () => void,
|
|
29
|
+
unhighlight: () => void,
|
|
30
|
+
updateProps: (select: 'leading' | 'trailing', newProps: Object) => void,
|
|
31
|
+
...
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type RenderItemProps<ItemT> = {
|
|
35
|
+
item: ItemT,
|
|
36
|
+
index: number,
|
|
37
|
+
separators: Separators,
|
|
38
|
+
...
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type CellRendererProps<ItemT> = $ReadOnly<{
|
|
42
|
+
cellKey: string,
|
|
43
|
+
children: React.Node,
|
|
44
|
+
index: number,
|
|
45
|
+
item: ItemT,
|
|
46
|
+
onFocusCapture?: (event: FocusEvent) => void,
|
|
47
|
+
onLayout?: (event: LayoutEvent) => void,
|
|
48
|
+
style: ViewStyleProp,
|
|
49
|
+
}>;
|
|
50
|
+
|
|
51
|
+
export type RenderItemType<ItemT> = (
|
|
52
|
+
info: RenderItemProps<ItemT>,
|
|
53
|
+
) => React.Node;
|
|
54
|
+
|
|
55
|
+
type RequiredProps = {|
|
|
56
|
+
/**
|
|
57
|
+
* The default accessor functions assume this is an Array<{key: string} | {id: string}> but you can override
|
|
58
|
+
* getItem, getItemCount, and keyExtractor to handle any type of index-based data.
|
|
59
|
+
*/
|
|
60
|
+
data?: any,
|
|
61
|
+
/**
|
|
62
|
+
* A generic accessor for extracting an item from any sort of data blob.
|
|
63
|
+
*/
|
|
64
|
+
getItem: (data: any, index: number) => ?Item,
|
|
65
|
+
/**
|
|
66
|
+
* Determines how many items are in the data blob.
|
|
67
|
+
*/
|
|
68
|
+
getItemCount: (data: any) => number,
|
|
69
|
+
|};
|
|
70
|
+
type OptionalProps = {|
|
|
71
|
+
renderItem?: ?RenderItemType<Item>,
|
|
72
|
+
/**
|
|
73
|
+
* `debug` will turn on extra logging and visual overlays to aid with debugging both usage and
|
|
74
|
+
* implementation, but with a significant perf hit.
|
|
75
|
+
*/
|
|
76
|
+
debug?: ?boolean,
|
|
77
|
+
/**
|
|
78
|
+
* DEPRECATED: Virtualization provides significant performance and memory optimizations, but fully
|
|
79
|
+
* unmounts react instances that are outside of the render window. You should only need to disable
|
|
80
|
+
* this for debugging purposes. Defaults to false.
|
|
81
|
+
*/
|
|
82
|
+
disableVirtualization?: ?boolean,
|
|
83
|
+
/**
|
|
84
|
+
* A marker property for telling the list to re-render (since it implements `PureComponent`). If
|
|
85
|
+
* any of your `renderItem`, Header, Footer, etc. functions depend on anything outside of the
|
|
86
|
+
* `data` prop, stick it here and treat it immutably.
|
|
87
|
+
*/
|
|
88
|
+
extraData?: any,
|
|
89
|
+
// e.g. height, y
|
|
90
|
+
getItemLayout?: (
|
|
91
|
+
data: any,
|
|
92
|
+
index: number,
|
|
93
|
+
) => {
|
|
94
|
+
length: number,
|
|
95
|
+
offset: number,
|
|
96
|
+
index: number,
|
|
97
|
+
...
|
|
98
|
+
},
|
|
99
|
+
horizontal?: ?boolean,
|
|
100
|
+
/**
|
|
101
|
+
* How many items to render in the initial batch. This should be enough to fill the screen but not
|
|
102
|
+
* much more. Note these items will never be unmounted as part of the windowed rendering in order
|
|
103
|
+
* to improve perceived performance of scroll-to-top actions.
|
|
104
|
+
*/
|
|
105
|
+
initialNumToRender?: ?number,
|
|
106
|
+
/**
|
|
107
|
+
* Instead of starting at the top with the first item, start at `initialScrollIndex`. This
|
|
108
|
+
* disables the "scroll to top" optimization that keeps the first `initialNumToRender` items
|
|
109
|
+
* always rendered and immediately renders the items starting at this initial index. Requires
|
|
110
|
+
* `getItemLayout` to be implemented.
|
|
111
|
+
*/
|
|
112
|
+
initialScrollIndex?: ?number,
|
|
113
|
+
/**
|
|
114
|
+
* Reverses the direction of scroll. Uses scale transforms of -1.
|
|
115
|
+
*/
|
|
116
|
+
inverted?: ?boolean,
|
|
117
|
+
keyExtractor?: ?(item: Item, index: number) => string,
|
|
118
|
+
/**
|
|
119
|
+
* CellRendererComponent allows customizing how cells rendered by
|
|
120
|
+
* `renderItem`/`ListItemComponent` are wrapped when placed into the
|
|
121
|
+
* underlying ScrollView. This component must accept event handlers which
|
|
122
|
+
* notify VirtualizedList of changes within the cell.
|
|
123
|
+
*/
|
|
124
|
+
CellRendererComponent?: ?React.ComponentType<CellRendererProps<Item>>,
|
|
125
|
+
/**
|
|
126
|
+
* Rendered in between each item, but not at the top or bottom. By default, `highlighted` and
|
|
127
|
+
* `leadingItem` props are provided. `renderItem` provides `separators.highlight`/`unhighlight`
|
|
128
|
+
* which will update the `highlighted` prop, but you can also add custom props with
|
|
129
|
+
* `separators.updateProps`.
|
|
130
|
+
*/
|
|
131
|
+
ItemSeparatorComponent?: ?React.ComponentType<any>,
|
|
132
|
+
/**
|
|
133
|
+
* Takes an item from `data` and renders it into the list. Example usage:
|
|
134
|
+
*
|
|
135
|
+
* <FlatList
|
|
136
|
+
* ItemSeparatorComponent={Platform.OS !== 'android' && ({highlighted}) => (
|
|
137
|
+
* <View style={[style.separator, highlighted && {marginLeft: 0}]} />
|
|
138
|
+
* )}
|
|
139
|
+
* data={[{title: 'Title Text', key: 'item1'}]}
|
|
140
|
+
* ListItemComponent={({item, separators}) => (
|
|
141
|
+
* <TouchableHighlight
|
|
142
|
+
* onPress={() => this._onPress(item)}
|
|
143
|
+
* onShowUnderlay={separators.highlight}
|
|
144
|
+
* onHideUnderlay={separators.unhighlight}>
|
|
145
|
+
* <View style={{backgroundColor: 'white'}}>
|
|
146
|
+
* <Text>{item.title}</Text>
|
|
147
|
+
* </View>
|
|
148
|
+
* </TouchableHighlight>
|
|
149
|
+
* )}
|
|
150
|
+
* />
|
|
151
|
+
*
|
|
152
|
+
* Provides additional metadata like `index` if you need it, as well as a more generic
|
|
153
|
+
* `separators.updateProps` function which let's you set whatever props you want to change the
|
|
154
|
+
* rendering of either the leading separator or trailing separator in case the more common
|
|
155
|
+
* `highlight` and `unhighlight` (which set the `highlighted: boolean` prop) are insufficient for
|
|
156
|
+
* your use-case.
|
|
157
|
+
*/
|
|
158
|
+
ListItemComponent?: ?(React.ComponentType<any> | React.Element<any>),
|
|
159
|
+
/**
|
|
160
|
+
* Rendered when the list is empty. Can be a React Component Class, a render function, or
|
|
161
|
+
* a rendered element.
|
|
162
|
+
*/
|
|
163
|
+
ListEmptyComponent?: ?(React.ComponentType<any> | React.Element<any>),
|
|
164
|
+
/**
|
|
165
|
+
* Rendered at the bottom of all the items. Can be a React Component Class, a render function, or
|
|
166
|
+
* a rendered element.
|
|
167
|
+
*/
|
|
168
|
+
ListFooterComponent?: ?(React.ComponentType<any> | React.Element<any>),
|
|
169
|
+
/**
|
|
170
|
+
* Styling for internal View for ListFooterComponent
|
|
171
|
+
*/
|
|
172
|
+
ListFooterComponentStyle?: ViewStyleProp,
|
|
173
|
+
/**
|
|
174
|
+
* Rendered at the top of all the items. Can be a React Component Class, a render function, or
|
|
175
|
+
* a rendered element.
|
|
176
|
+
*/
|
|
177
|
+
ListHeaderComponent?: ?(React.ComponentType<any> | React.Element<any>),
|
|
178
|
+
/**
|
|
179
|
+
* Styling for internal View for ListHeaderComponent
|
|
180
|
+
*/
|
|
181
|
+
ListHeaderComponentStyle?: ViewStyleProp,
|
|
182
|
+
/**
|
|
183
|
+
* The maximum number of items to render in each incremental render batch. The more rendered at
|
|
184
|
+
* once, the better the fill rate, but responsiveness may suffer because rendering content may
|
|
185
|
+
* interfere with responding to button taps or other interactions.
|
|
186
|
+
*/
|
|
187
|
+
maxToRenderPerBatch?: ?number,
|
|
188
|
+
/**
|
|
189
|
+
* Called once when the scroll position gets within within `onEndReachedThreshold`
|
|
190
|
+
* from the logical end of the list.
|
|
191
|
+
*/
|
|
192
|
+
onEndReached?: ?(info: {distanceFromEnd: number, ...}) => void,
|
|
193
|
+
/**
|
|
194
|
+
* How far from the end (in units of visible length of the list) the trailing edge of the
|
|
195
|
+
* list must be from the end of the content to trigger the `onEndReached` callback.
|
|
196
|
+
* Thus, a value of 0.5 will trigger `onEndReached` when the end of the content is
|
|
197
|
+
* within half the visible length of the list.
|
|
198
|
+
*/
|
|
199
|
+
onEndReachedThreshold?: ?number,
|
|
200
|
+
/**
|
|
201
|
+
* If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality. Make
|
|
202
|
+
* sure to also set the `refreshing` prop correctly.
|
|
203
|
+
*/
|
|
204
|
+
onRefresh?: ?() => void,
|
|
205
|
+
/**
|
|
206
|
+
* Used to handle failures when scrolling to an index that has not been measured yet. Recommended
|
|
207
|
+
* action is to either compute your own offset and `scrollTo` it, or scroll as far as possible and
|
|
208
|
+
* then try again after more items have been rendered.
|
|
209
|
+
*/
|
|
210
|
+
onScrollToIndexFailed?: ?(info: {
|
|
211
|
+
index: number,
|
|
212
|
+
highestMeasuredFrameIndex: number,
|
|
213
|
+
averageItemLength: number,
|
|
214
|
+
...
|
|
215
|
+
}) => void,
|
|
216
|
+
/**
|
|
217
|
+
* Called once when the scroll position gets within within `onStartReachedThreshold`
|
|
218
|
+
* from the logical start of the list.
|
|
219
|
+
*/
|
|
220
|
+
onStartReached?: ?(info: {distanceFromStart: number, ...}) => void,
|
|
221
|
+
/**
|
|
222
|
+
* How far from the start (in units of visible length of the list) the leading edge of the
|
|
223
|
+
* list must be from the start of the content to trigger the `onStartReached` callback.
|
|
224
|
+
* Thus, a value of 0.5 will trigger `onStartReached` when the start of the content is
|
|
225
|
+
* within half the visible length of the list.
|
|
226
|
+
*/
|
|
227
|
+
onStartReachedThreshold?: ?number,
|
|
228
|
+
/**
|
|
229
|
+
* Called when the viewability of rows changes, as defined by the
|
|
230
|
+
* `viewabilityConfig` prop.
|
|
231
|
+
*/
|
|
232
|
+
onViewableItemsChanged?: ?(info: {
|
|
233
|
+
viewableItems: Array<ViewToken>,
|
|
234
|
+
changed: Array<ViewToken>,
|
|
235
|
+
...
|
|
236
|
+
}) => void,
|
|
237
|
+
persistentScrollbar?: ?boolean,
|
|
238
|
+
/**
|
|
239
|
+
* Set this when offset is needed for the loading indicator to show correctly.
|
|
240
|
+
*/
|
|
241
|
+
progressViewOffset?: number,
|
|
242
|
+
/**
|
|
243
|
+
* A custom refresh control element. When set, it overrides the default
|
|
244
|
+
* <RefreshControl> component built internally. The onRefresh and refreshing
|
|
245
|
+
* props are also ignored. Only works for vertical VirtualizedList.
|
|
246
|
+
*/
|
|
247
|
+
refreshControl?: ?React.Element<any>,
|
|
248
|
+
/**
|
|
249
|
+
* Set this true while waiting for new data from a refresh.
|
|
250
|
+
*/
|
|
251
|
+
refreshing?: ?boolean,
|
|
252
|
+
/**
|
|
253
|
+
* Note: may have bugs (missing content) in some circumstances - use at your own risk.
|
|
254
|
+
*
|
|
255
|
+
* This may improve scroll performance for large lists.
|
|
256
|
+
*/
|
|
257
|
+
removeClippedSubviews?: boolean,
|
|
258
|
+
/**
|
|
259
|
+
* Render a custom scroll component, e.g. with a differently styled `RefreshControl`.
|
|
260
|
+
*/
|
|
261
|
+
renderScrollComponent?: (props: Object) => React.Element<any>,
|
|
262
|
+
/**
|
|
263
|
+
* Amount of time between low-pri item render batches, e.g. for rendering items quite a ways off
|
|
264
|
+
* screen. Similar fill rate/responsiveness tradeoff as `maxToRenderPerBatch`.
|
|
265
|
+
*/
|
|
266
|
+
updateCellsBatchingPeriod?: ?number,
|
|
267
|
+
/**
|
|
268
|
+
* See `ViewabilityHelper` for flow type and further documentation.
|
|
269
|
+
*/
|
|
270
|
+
viewabilityConfig?: ViewabilityConfig,
|
|
271
|
+
/**
|
|
272
|
+
* List of ViewabilityConfig/onViewableItemsChanged pairs. A specific onViewableItemsChanged
|
|
273
|
+
* will be called when its corresponding ViewabilityConfig's conditions are met.
|
|
274
|
+
*/
|
|
275
|
+
viewabilityConfigCallbackPairs?: Array<ViewabilityConfigCallbackPair>,
|
|
276
|
+
/**
|
|
277
|
+
* Determines the maximum number of items rendered outside of the visible area, in units of
|
|
278
|
+
* visible lengths. So if your list fills the screen, then `windowSize={21}` (the default) will
|
|
279
|
+
* render the visible screen area plus up to 10 screens above and 10 below the viewport. Reducing
|
|
280
|
+
* this number will reduce memory consumption and may improve performance, but will increase the
|
|
281
|
+
* chance that fast scrolling may reveal momentary blank areas of unrendered content.
|
|
282
|
+
*/
|
|
283
|
+
windowSize?: ?number,
|
|
284
|
+
/**
|
|
285
|
+
* The legacy implementation is no longer supported.
|
|
286
|
+
*/
|
|
287
|
+
legacyImplementation?: empty,
|
|
288
|
+
|};
|
|
289
|
+
|
|
290
|
+
export type Props = {|
|
|
291
|
+
...React.ElementConfig<ScrollView>,
|
|
292
|
+
...RequiredProps,
|
|
293
|
+
...OptionalProps,
|
|
294
|
+
|};
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Default Props Helper Functions
|
|
298
|
+
* Use the following helper functions for default values
|
|
299
|
+
*/
|
|
300
|
+
|
|
301
|
+
// horizontalOrDefault(this.props.horizontal)
|
|
302
|
+
export function horizontalOrDefault(horizontal: ?boolean): boolean {
|
|
303
|
+
return horizontal ?? false;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// initialNumToRenderOrDefault(this.props.initialNumToRender)
|
|
307
|
+
export function initialNumToRenderOrDefault(
|
|
308
|
+
initialNumToRender: ?number,
|
|
309
|
+
): number {
|
|
310
|
+
return initialNumToRender ?? 10;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// maxToRenderPerBatchOrDefault(this.props.maxToRenderPerBatch)
|
|
314
|
+
export function maxToRenderPerBatchOrDefault(
|
|
315
|
+
maxToRenderPerBatch: ?number,
|
|
316
|
+
): number {
|
|
317
|
+
return maxToRenderPerBatch ?? 10;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// onStartReachedThresholdOrDefault(this.props.onStartReachedThreshold)
|
|
321
|
+
export function onStartReachedThresholdOrDefault(
|
|
322
|
+
onStartReachedThreshold: ?number,
|
|
323
|
+
): number {
|
|
324
|
+
return onStartReachedThreshold ?? 2;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// onEndReachedThresholdOrDefault(this.props.onEndReachedThreshold)
|
|
328
|
+
export function onEndReachedThresholdOrDefault(
|
|
329
|
+
onEndReachedThreshold: ?number,
|
|
330
|
+
): number {
|
|
331
|
+
return onEndReachedThreshold ?? 2;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// windowSizeOrDefault(this.props.windowSize)
|
|
335
|
+
export function windowSizeOrDefault(windowSize: ?number): number {
|
|
336
|
+
return windowSize ?? 21;
|
|
337
|
+
}
|