Skip to content

Commit 4c0f4cd

Browse files
committed
skip if miss similarity too many times
1 parent 903cf32 commit 4c0f4cd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/List.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,12 @@ class List<T> extends React.Component<ListProps<T>, ListState> {
194194
let bestStartIndex: number = null;
195195
let bestEndIndex: number = null;
196196

197+
let missSimilarity = 0;
198+
197199
const scrollHeight = dataSource.length * itemHeight;
198200
const { clientHeight } = this.listRef.current;
199201
const maxScrollTop = scrollHeight - clientHeight;
202+
200203
for (let i = 0; i < maxScrollTop; i += 1) {
201204
const scrollTop = getIndexByStartLoc(0, maxScrollTop, originScrollTop, i);
202205

@@ -240,8 +243,19 @@ class List<T> extends React.Component<ListProps<T>, ListState> {
240243
bestItemOffsetPtg = itemOffsetPtg;
241244
bestStartIndex = startIndex;
242245
bestEndIndex = endIndex;
246+
247+
missSimilarity = 0;
248+
} else {
249+
missSimilarity += 1;
243250
}
244251
}
252+
253+
// If keeping 10 times not match similarity,
254+
// check more scrollTop is meaningless.
255+
// Here boundary is set to 10.
256+
if (missSimilarity > 10) {
257+
break;
258+
}
245259
}
246260

247261
// 5. Re-scroll if has best scroll match

0 commit comments

Comments
 (0)