@@ -14,6 +14,7 @@ import type {ScrollResponderType} from '../Components/ScrollView/ScrollView';
14
14
import type {
15
15
ScrollToLocationParamsType ,
16
16
SectionBase as _SectionBase ,
17
+ SectionData ,
17
18
VirtualizedSectionListProps ,
18
19
} from '@react-native/virtualized-lists' ;
19
20
import type { ElementRef } from 'react' ;
@@ -24,11 +25,16 @@ import React, {forwardRef, useImperativeHandle, useRef} from 'react';
24
25
25
26
const VirtualizedSectionList = VirtualizedLists . VirtualizedSectionList ;
26
27
27
- type Item = any ;
28
+ type DefaultSectionT = {
29
+ [ key : string ] : any ,
30
+ } ;
28
31
29
- export type SectionBase < SectionItemT > = _SectionBase < SectionItemT > ;
32
+ export type SectionBase <
33
+ SectionItemT ,
34
+ SectionT = DefaultSectionT ,
35
+ > = _SectionBase < SectionItemT , SectionT > ;
30
36
31
- type RequiredProps < SectionT : SectionBase < any > > = {
37
+ type RequiredProps < ItemT , SectionT = DefaultSectionT > = {
32
38
/**
33
39
* The actual data to render, akin to the `data` prop in [`<FlatList>`](https://reactnative.dev/docs/flatlist).
34
40
*
@@ -40,17 +46,17 @@ type RequiredProps<SectionT: SectionBase<any>> = {
40
46
* ItemSeparatorComponent?: ?ReactClass<{highlighted: boolean, ...}>,
41
47
* }>
42
48
*/
43
- sections : $ReadOnlyArray < SectionT > ,
49
+ sections : $ReadOnlyArray < SectionData < ItemT , SectionT> >,
44
50
} ;
45
51
46
- type OptionalProps < SectionT : SectionBase < any > > = {
52
+ type OptionalProps < ItemT , SectionT = DefaultSectionT > = {
47
53
/**
48
54
* Default renderer for every item in every section. Can be over-ridden on a per-section basis.
49
55
*/
50
56
renderItem ?: ( info : {
51
- item : Item ,
57
+ item : ItemT ,
52
58
index : number ,
53
- section : SectionT ,
59
+ section : SectionData < ItemT , SectionT> ,
54
60
separators : {
55
61
highlight : ( ) => void ,
56
62
unhighlight : ( ) => void ,
@@ -81,7 +87,7 @@ type OptionalProps<SectionT: SectionBase<any>> = {
81
87
* falls back to using the index, like react does. Note that this sets keys for each item, but
82
88
* each overall section still needs its own key.
83
89
*/
84
- keyExtractor ?: ?( item : Item , index : number ) => string ,
90
+ keyExtractor ?: ?( item : ItemT , index : number ) => string ,
85
91
/**
86
92
* Called once when the scroll position gets within `onEndReachedThreshold` of the rendered
87
93
* content.
@@ -95,28 +101,31 @@ type OptionalProps<SectionT: SectionBase<any>> = {
95
101
removeClippedSubviews ?: boolean ,
96
102
} ;
97
103
98
- export type Props < SectionT : SectionBase < any > > = $ReadOnly < {
104
+ export type Props < ItemT , SectionT = DefaultSectionT > = $ReadOnly < {
99
105
...$Diff <
100
- VirtualizedSectionListProps < SectionT > ,
106
+ VirtualizedSectionListProps < ItemT , SectionT> ,
101
107
{
102
- getItem : $PropertyType < VirtualizedSectionListProps < SectionT > , 'getItem' > ,
108
+ getItem : $PropertyType <
109
+ VirtualizedSectionListProps < ItemT , SectionT> ,
110
+ 'getItem' ,
111
+ > ,
103
112
getItemCount : $PropertyType <
104
- VirtualizedSectionListProps < SectionT > ,
113
+ VirtualizedSectionListProps < ItemT , SectionT> ,
105
114
'getItemCount' ,
106
115
> ,
107
116
renderItem : $PropertyType <
108
- VirtualizedSectionListProps < SectionT > ,
117
+ VirtualizedSectionListProps < ItemT , SectionT> ,
109
118
'renderItem' ,
110
119
> ,
111
120
keyExtractor : $PropertyType <
112
- VirtualizedSectionListProps < SectionT > ,
121
+ VirtualizedSectionListProps < ItemT , SectionT> ,
113
122
'keyExtractor' ,
114
123
> ,
115
124
...
116
125
} ,
117
126
> ,
118
- ...RequiredProps < SectionT > ,
119
- ...OptionalProps < SectionT > ,
127
+ ...RequiredProps < ItemT , SectionT> ,
128
+ ...OptionalProps < ItemT , SectionT> ,
120
129
} > ;
121
130
122
131
/**
@@ -176,8 +185,8 @@ export type Props<SectionT: SectionBase<any>> = $ReadOnly<{
176
185
*/
177
186
const SectionList : component (
178
187
ref ?: React . RefSetter < any > ,
179
- ...Props < SectionBase < any > >
180
- ) = forwardRef < Props < SectionBase < any > >, any > ( ( props , ref ) => {
188
+ ...Props < any , DefaultSectionT >
189
+ ) = forwardRef < Props < any , DefaultSectionT > , any > ( ( props , ref ) => {
181
190
const propsWithDefaults = {
182
191
stickySectionHeadersEnabled : Platform . OS === 'ios' ,
183
192
...props ,
0 commit comments