Browse Source

Fix for wrong ref call order

master v1.0.14
Vitaliy Filippov 2 years ago
parent
commit
ea707b2c08
  1. 6
      DynamicVirtualScroll.js
  2. 14
      VirtualScrollList.js
  3. 2
      package.json

6
DynamicVirtualScroll.js

@ -61,8 +61,10 @@ export function virtualScrollDriver(props, oldState, getRenderedItemHeight)
lastItemSize = getRenderedItemHeight(props.totalItems - 1 - lastVisibleItems);
if (!lastItemSize)
{
// Some required items in the end are missing
return newState;
// Some required items in the end are missing, complain about it loudly, but don't break scrolling
// eslint-disable-next-line
console.error('dynamic-virtual-scroll: item #'+(props.totalItems - 1 - lastVisibleItems)+' is missing from render, please fix your code');
lastItemSize = 0;
}
lastItemsHeight += lastItemSize < props.minRowHeight ? props.minRowHeight : lastItemSize;
lastVisibleItems++;

14
VirtualScrollList.js

@ -36,10 +36,22 @@ export class VirtualScrollList extends React.Component
setItemRef = []
itemRefs = []
itemRefCount = []
makeRef(i)
{
this.setItemRef[i] = (e) => this.itemRefs[i] = e;
this.setItemRef[i] = (e) =>
{
// If the new row instance is mounted before unmouting the old one,
// we get called 2 times in wrong order: first with the new instance,
// then with null telling us that the old one is unmounted.
// We track reference count to workaround it.
this.itemRefCount[i] = (this.itemRefCount[i]||0) + (e ? 1 : -1);
if (e || !this.itemRefCount[i])
{
this.itemRefs[i] = e;
}
};
}
renderItems(start, count, is_end)

2
package.json

@ -1,6 +1,6 @@
{
"name": "dynamic-virtual-scroll",
"version": "1.0.13",
"version": "1.0.14",
"author": {
"name": "Vitaliy Filippov",
"email": "vitalif@yourcmc.ru",

Loading…
Cancel
Save