@@ -152,23 +152,35 @@ class List<T> extends React.Component<ListProps<T>, ListState> {
152
152
153
153
let originCompareItemIndex = removedItemIndex - 1 ;
154
154
if ( originCompareItemIndex >= originItemIndex ) originCompareItemIndex = originItemIndex ;
155
- const compareItemKey = this . getItemKey ( originCompareItemIndex , prevProps ) ;
156
155
156
+ // Find compare item key & offset top
157
+ let compareItemIndex : number ;
158
+ let compareItemKey : string ;
157
159
let originCompareItemTop = this . state . startItemTop ;
158
- for ( let index = originStartIndex ; index <= originItemIndex ; index += 1 ) {
159
- const key = this . getItemKey ( index , prevProps ) ;
160
- if ( key === compareItemKey ) {
161
- break ;
160
+ if ( originCompareItemIndex < 0 ) {
161
+ // If remove item is the first one, we have compare next one
162
+ originCompareItemIndex = 0 ;
163
+ compareItemIndex = 0 ;
164
+ compareItemKey = this . getItemKey ( compareItemIndex ) ;
165
+ } else {
166
+ // If exist compare item
167
+ compareItemKey = this . getItemKey ( originCompareItemIndex , prevProps ) ;
168
+
169
+ for ( let index = originStartIndex ; index <= originItemIndex ; index += 1 ) {
170
+ const key = this . getItemKey ( index , prevProps ) ;
171
+ if ( key === compareItemKey ) {
172
+ break ;
173
+ }
174
+
175
+ originCompareItemTop += this . itemElementHeights [ key ] || 0 ;
162
176
}
163
177
164
- originCompareItemTop += this . itemElementHeights [ key ] || 0 ;
178
+ // Find current compare item index
179
+ compareItemIndex = dataSource . findIndex (
180
+ ( _ , index ) => this . getItemKey ( index ) === compareItemKey ,
181
+ ) ;
165
182
}
166
183
167
- // Find current compare item index
168
- const compareItemIndex = dataSource . findIndex (
169
- ( _ , index ) => this . getItemKey ( index ) === compareItemKey ,
170
- ) ;
171
-
172
184
// Loop to generate compared item top and find best one
173
185
const { scrollHeight, clientHeight } = this . listRef . current ;
174
186
const maxScrollTop = scrollHeight - clientHeight ;
0 commit comments