diff --git a/src/core/VirtualRenderer.ts b/src/core/VirtualRenderer.ts index c6cdfc95..29025674 100644 --- a/src/core/VirtualRenderer.ts +++ b/src/core/VirtualRenderer.ts @@ -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; @@ -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; @@ -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 @@ -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; @@ -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); + } } } } diff --git a/src/core/dependencies/DataProvider.ts b/src/core/dependencies/DataProvider.ts index 5fffb4ea..4cf7ba6e 100644 --- a/src/core/dependencies/DataProvider.ts +++ b/src/core/dependencies/DataProvider.ts @@ -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); @@ -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; diff --git a/src/core/sticky/StickyHeader.tsx b/src/core/sticky/StickyHeader.tsx index 522072e6..f56ba950 100644 --- a/src/core/sticky/StickyHeader.tsx +++ b/src/core/sticky/StickyHeader.tsx @@ -62,7 +62,6 @@ export default class StickyHeader

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; } }