@infinite-list/data-model
Advanced tools
Comparing version 0.2.45-recycle-group.35 to 0.2.45-recycle-group.36
@@ -38,2 +38,3 @@ import Batchinator from '@x-oasis/batchinator'; | ||
private _provider; | ||
private _releaseSpaceStateItem; | ||
constructor(props: ListBaseDimensionsProps<ItemT>); | ||
@@ -76,2 +77,3 @@ initializeDefaultRecycleBuffer(): void; | ||
getFinalIndexKeyOffset(index: number): number; | ||
getFinalIndexKeyBottomOffset(index: number): number; | ||
hasUnLayoutItems(): boolean; | ||
@@ -78,0 +80,0 @@ computeIndexRange(minOffset: number, maxOffset: number): { |
@@ -62,2 +62,3 @@ import Batchinator from '@x-oasis/batchinator'; | ||
getFinalIndexKeyOffset(index: number, exclusive?: boolean): number; | ||
getFinalIndexKeyBottomOffset(index: number, exclusive?: boolean): number; | ||
getFinalIndexRangeOffsetMap(startIndex: number, endIndex: number, exclusive?: boolean): {}; | ||
@@ -64,0 +65,0 @@ getFinalIndexItemLength(index: number): number; |
@@ -45,2 +45,3 @@ import Dimension from '../Dimension'; | ||
onRecyclerProcess?: OnRecyclerProcess; | ||
releaseSpaceStateItem?: boolean; | ||
}; | ||
@@ -47,0 +48,0 @@ export declare type BaseDimensionsProps = { |
{ | ||
"name": "@infinite-list/data-model", | ||
"version": "0.2.45-recycle-group.35", | ||
"version": "0.2.45-recycle-group.36", | ||
"files": [ | ||
@@ -5,0 +5,0 @@ "dist", |
@@ -116,2 +116,4 @@ import noop from '@x-oasis/noop'; | ||
private _releaseSpaceStateItem: boolean; | ||
constructor(props: ListBaseDimensionsProps<ItemT>) { | ||
@@ -155,2 +157,4 @@ super(props); | ||
releaseSpaceStateItem = false, | ||
maxCountOfHandleOnEndReachedAfterStillness, | ||
@@ -163,2 +167,3 @@ } = props; | ||
this._onRecyclerProcess = onRecyclerProcess; | ||
this._releaseSpaceStateItem = releaseSpaceStateItem; | ||
@@ -418,2 +423,6 @@ // `_approximateMode` is enabled on default | ||
getFinalIndexKeyBottomOffset(index: number) { | ||
return this._provider.getFinalIndexKeyBottomOffset(index); | ||
} | ||
hasUnLayoutItems() { | ||
@@ -809,2 +818,57 @@ return this.getReflowItemsLength() < this._data.length; | ||
resolveRecycleSpaceState(state: ListState<ItemT>) { | ||
if (!this._releaseSpaceStateItem) { | ||
const nextData = this._data.slice(0, this.initialNumToRender); | ||
const spaceState = []; | ||
for (let index = 0; index < nextData.length; index++) { | ||
const item = this._data[index]; | ||
const itemMeta = this.getFinalItemMeta(item); | ||
if (itemMeta) | ||
spaceState.push({ | ||
item, | ||
isSpace: false, | ||
itemMeta, | ||
key: itemMeta.getKey(), | ||
isSticky: false, | ||
isReserved: true, | ||
length: this.getFinalIndexItemLength(index), | ||
}); | ||
} | ||
const afterTokens = this.resolveToken( | ||
this.initialNumToRender, | ||
this._data.length - 1 | ||
); | ||
afterTokens.forEach((token) => { | ||
const { isSticky, isReserved, startIndex, endIndex } = token; | ||
if (isSticky || isReserved) { | ||
const item = this._data[startIndex]; | ||
const itemMeta = this.getFinalItemMeta(item); | ||
spaceState.push({ | ||
item, | ||
isSpace: false, | ||
key: itemMeta.getKey(), | ||
itemMeta, | ||
isSticky, | ||
isReserved, | ||
length: this.getFinalIndexItemLength(startIndex), | ||
}); | ||
} else { | ||
const startIndexOffset = this.getFinalIndexKeyOffset(startIndex); | ||
// should plus 1, use list total length | ||
const endIndexOffset = this.getFinalIndexKeyBottomOffset(endIndex); | ||
spaceState.push({ | ||
item: null, | ||
isSpace: true, | ||
isSticky: false, | ||
isReserved: false, | ||
length: endIndexOffset - startIndexOffset, | ||
// endIndex is not included | ||
itemMeta: null, | ||
key: buildStateTokenIndexKey(startIndex, endIndex - 1), | ||
}); | ||
} | ||
}); | ||
return spaceState; | ||
} | ||
return this.resolveSpaceState(state, { | ||
@@ -936,3 +1000,3 @@ bufferedStartIndex: (state) => | ||
const startIndexOffset = this.getFinalIndexKeyOffset(startIndex); | ||
const endIndexOffset = this.getFinalIndexKeyOffset(endIndex); | ||
const endIndexOffset = this.getFinalIndexKeyBottomOffset(endIndex); | ||
spaceState.push({ | ||
@@ -954,12 +1018,12 @@ item: null, | ||
updateState(newState: PreStateResult, scrollMetrics: ScrollMetrics) { | ||
const { | ||
bufferedStartIndex: nextBufferedStartIndex, | ||
bufferedEndIndex: nextBufferedEndIndex, | ||
} = newState; | ||
// const { | ||
// bufferedStartIndex: nextBufferedStartIndex, | ||
// bufferedEndIndex: nextBufferedEndIndex, | ||
// } = newState; | ||
const omitKeys = ['data', 'distanceFromEnd', 'isEndReached']; | ||
const nextDataLength = Math.max( | ||
nextBufferedEndIndex + 1, | ||
this.getReflowItemsLength() | ||
); | ||
// const nextDataLength = Math.max( | ||
// nextBufferedEndIndex + 1, | ||
// this.getReflowItemsLength() | ||
// ); | ||
@@ -966,0 +1030,0 @@ const oldData = this._state.data; |
@@ -287,2 +287,21 @@ import Batchinator from '@x-oasis/batchinator'; | ||
getFinalIndexKeyBottomOffset(index: number, exclusive?: boolean) { | ||
const listOffset = exclusive ? 0 : this.getContainerOffset(); | ||
if (typeof index === 'number') { | ||
const indexInfo = this.getFinalIndexIndexInfo(index); | ||
if (indexInfo) { | ||
const { dimensions, index: _index } = indexInfo; | ||
const height = dimensions.getTotalLength(); | ||
// _offsetInListGroup should be included. so exclusive should be false on default. | ||
return ( | ||
listOffset + | ||
dimensions.getContainerOffset() + | ||
(typeof height === 'number' ? height : 0) | ||
); | ||
} | ||
} | ||
return 0; | ||
} | ||
getFinalIndexRangeOffsetMap( | ||
@@ -289,0 +308,0 @@ startIndex: number, |
@@ -61,2 +61,3 @@ import Dimension from '../Dimension'; | ||
onRecyclerProcess?: OnRecyclerProcess; | ||
releaseSpaceStateItem?: boolean; | ||
}; | ||
@@ -63,0 +64,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
2639166
34404