Skip to content

Commit 36b3294

Browse files
authored
fix: new views not used immediately (#391)
* refactor: Slide unusedIndex variable * refactor: Pull unusedPool up * fix: Every other item gets a new view created
1 parent 120eb92 commit 36b3294

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

src/components/RecycleScroller.vue

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ export default {
372372
let view
373373
374374
const continuous = startIndex <= this.$_endIndex && endIndex >= this.$_startIndex
375-
let unusedIndex
376375
377376
if (this.$_continuous !== continuous) {
378377
if (continuous) {
@@ -407,9 +406,7 @@ export default {
407406
}
408407
}
409408
410-
if (!continuous) {
411-
unusedIndex = new Map()
412-
}
409+
let unusedIndex = continuous ? null : new Map();
413410
414411
let item, type, unusedPool
415412
let v
@@ -429,9 +426,9 @@ export default {
429426
// No view assigned to item
430427
if (!view) {
431428
type = item[typeField]
429+
unusedPool = unusedViews.get(type)
432430
433431
if (continuous) {
434-
unusedPool = unusedViews.get(type)
435432
// Reuse existing view
436433
if (unusedPool && unusedPool.length) {
437434
view = unusedPool.pop()
@@ -444,23 +441,21 @@ export default {
444441
view = this.addView(pool, i, item, key, type)
445442
}
446443
} else {
447-
unusedPool = unusedViews.get(type)
448-
v = unusedIndex.get(type) || 0
449-
// Use existing view
450-
// We don't care if they are already used
451-
// because we are not in continous scrolling
452-
if (unusedPool && v < unusedPool.length) {
453-
view = unusedPool[v]
454-
view.item = item
455-
view.nr.used = true
456-
view.nr.index = i
457-
view.nr.key = key
458-
view.nr.type = type
459-
unusedIndex.set(type, v + 1)
460-
} else {
444+
if (!unusedPool || v >= unusedPool.length) {
461445
view = this.addView(pool, i, item, key, type)
462446
this.unuseView(view, true)
463447
}
448+
// Use existing view
449+
// We don't care if they are already used
450+
// because we are not in continous scrolling
451+
v = unusedIndex.get(type) || 0
452+
view = unusedPool[v]
453+
view.item = item
454+
view.nr.used = true
455+
view.nr.index = i
456+
view.nr.key = key
457+
view.nr.type = type
458+
unusedIndex.set(type, v + 1)
464459
v++
465460
}
466461
views.set(key, view)

0 commit comments

Comments
 (0)