Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better optimizeForInsertDeleteAnimations and fix stableId collision #479

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
27 changes: 19 additions & 8 deletions src/core/VirtualRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default class VirtualRenderer {
private _stableIdToRenderKeyMap: { [key: string]: StableIdMapItem | undefined };
private _engagedIndexes: { [key: number]: number | undefined };
private _renderStack: RenderStack;
private _cachedRenderStack: RenderStack;
private _renderStackChanged: (renderStack: RenderStack) => void;
private _fetchStableId: StableIdProvider;
private _isRecyclingEnabled: boolean;
Expand All @@ -58,6 +59,7 @@ export default class VirtualRenderer {
isRecyclingEnabled: boolean) {
//Keeps track of items that need to be rendered in the next render cycle
this._renderStack = {};
this._cachedRenderStack = {};

this._fetchStableId = fetchStableId;

Expand Down Expand Up @@ -225,6 +227,10 @@ export default class VirtualRenderer {
}
} else {
key = getStableId(index);
if (this._cachedRenderStack[key]) {
delete this._cachedRenderStack[key];
key = this._getCollisionAvoidingKey();
}
if (renderStack[key]) {
//Probable collision, warn and avoid
//TODO: Disabled incorrectly triggering in some cases
Expand Down Expand Up @@ -282,7 +288,10 @@ export default class VirtualRenderer {
delete this._stableIdToRenderKeyMap[key];
}
}

if (shouldOptimizeForAnimations && this._isRecyclingEnabled && this._recyclePool) {
this._recyclePool.clearAll();
}
this._cachedRenderStack = Object.assign({}, this._renderStack);
for (const key in this._renderStack) {
if (this._renderStack.hasOwnProperty(key)) {
const index = this._renderStack[key].dataIndex;
Expand All @@ -304,14 +313,16 @@ export default class VirtualRenderer {
delete this._renderStack[key];
}
}
this._cachedRenderStack = {};
Object.assign(this._renderStack, newRenderStack);

for (const key in this._renderStack) {
if (this._renderStack.hasOwnProperty(key)) {
const index = this._renderStack[key].dataIndex;
if (!ObjectUtil.isNullOrUndefined(index) && ObjectUtil.isNullOrUndefined(this._engagedIndexes[index])) {
const type = this._layoutProvider.getLayoutTypeForIndex(index);
this._recyclePool.putRecycledObject(type, key);
if (!shouldOptimizeForAnimations && this._isRecyclingEnabled) {
for (const key in this._renderStack) {
if (this._renderStack.hasOwnProperty(key)) {
const index = this._renderStack[key].dataIndex;
if (!ObjectUtil.isNullOrUndefined(index) && ObjectUtil.isNullOrUndefined(this._engagedIndexes[index])) {
const type = this._layoutProvider.getLayoutTypeForIndex(index);
this._recyclePool.putRecycledObject(type, key);
}
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/core/dependencies/DataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export abstract class BaseDataProvider {

//No need to override this one
//If you already know the first row where rowHasChanged will be false pass it upfront to avoid loop
public cloneWithRows(newData: any[], firstModifiedIndex?: number): DataProvider {
public cloneWithRows(newData: any[], firstModifiedIndex?: number, optimizeForInsertAtBottomAnimation?: boolean): DataProvider {
const dp = this.newInstance(this.rowHasChanged, this.getStableId);
const newSize = newData.length;
const iterCount = Math.min(this._size, newSize);
Expand All @@ -70,6 +70,10 @@ export abstract class BaseDataProvider {
}
if (dp._firstIndexToProcess !== this._data.length) {
dp._requiresDataChangeHandling = true;
} else {
if (optimizeForInsertAtBottomAnimation && this._data.length < newSize) {
dp._requiresDataChangeHandling = true;
}
}
dp._data = newData;
dp._size = newSize;
Expand Down
3 changes: 1 addition & 2 deletions src/core/sticky/StickyHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export default class StickyHeader<P extends StickyObjectProps> extends StickyObj
}

protected hasReachedBoundary(offsetY: number, _windowBound?: number): boolean {
//TODO (Swapnil) Refer to talha and understand what needs to be done.
return false;
return offsetY <= 0;
}
}