6
6
getNodeHeight ,
7
7
getRangeIndex ,
8
8
getItemTop ,
9
+ GHOST_ITEM_KEY ,
9
10
} from './util' ;
10
11
11
12
type RenderFunc < T > = ( item : T ) => React . ReactNode ;
@@ -136,7 +137,12 @@ class List<T> extends React.Component<ListProps<T>, ListState> {
136
137
originStartItemTop += this . itemElementHeights [ key ] || 0 ;
137
138
}
138
139
139
- console . log ( 'Length changed. Origin top:' , originItemTops , this . state . startIndex ) ;
140
+ console . log (
141
+ 'Length changed. Origin top:' ,
142
+ originItemTops ,
143
+ this . state . startIndex ,
144
+ this . itemElementHeights ,
145
+ ) ;
140
146
141
147
// Loop to get the adjusted item top
142
148
const { scrollHeight, clientHeight } = this . listRef . current ;
@@ -151,7 +157,7 @@ class List<T> extends React.Component<ListProps<T>, ListState> {
151
157
visibleCount ,
152
158
) ;
153
159
154
- const locatedItemTop = getItemTop ( {
160
+ let locatedItemTop = getItemTop ( {
155
161
itemIndex,
156
162
itemOffsetPtg,
157
163
itemElementHeights : this . itemElementHeights ,
@@ -165,7 +171,7 @@ class List<T> extends React.Component<ListProps<T>, ListState> {
165
171
for ( let index = itemIndex ; index >= startIndex ; index -= 1 ) {
166
172
const key = this . getItemKey ( index ) ;
167
173
itemTops [ key ] = locatedItemTop ;
168
- originStartItemTop -= this . itemElementHeights [ key ] || 0 ;
174
+ locatedItemTop -= this . itemElementHeights [ key ] || 0 ;
169
175
}
170
176
171
177
console . log ( '=>' , scrollTop , itemTops ) ;
@@ -207,7 +213,16 @@ class List<T> extends React.Component<ListProps<T>, ListState> {
207
213
208
214
public getItemKey = ( index : number , props ?: ListProps < T > ) => {
209
215
const { dataSource, itemKey } = props || this . props ;
216
+
217
+ // Return ghost key as latest index item
218
+ if ( index === dataSource . length ) {
219
+ return GHOST_ITEM_KEY ;
220
+ }
221
+
210
222
const item = dataSource [ index ] ;
223
+ if ( ! item ) {
224
+ console . error ( 'Not find index item. Please report this since it is a bug.' ) ;
225
+ }
211
226
return item && itemKey ? item [ itemKey ] : index ;
212
227
} ;
213
228
0 commit comments