@infinite-list/data-model
Advanced tools
Comparing version 0.2.20-stillness.0 to 0.2.20-stillness.1
{ | ||
"name": "@infinite-list/data-model", | ||
"version": "0.2.20-stillness.0", | ||
"version": "0.2.20-stillness.1", | ||
"files": [ | ||
@@ -5,0 +5,0 @@ "dist", |
@@ -1011,2 +1011,3 @@ import noop from '@x-oasis/noop'; | ||
let _beforeCount = 0; | ||
let _topMinIndex = visibleStartIndex; | ||
@@ -1030,3 +1031,6 @@ for ( | ||
_topMinIndex = index; | ||
if (position !== null) targetIndices[position] = index; | ||
} else { | ||
break; | ||
} | ||
@@ -1040,2 +1044,3 @@ | ||
let _afterCount = 0; | ||
let _bottomMaxIndex = visibleEndIndex + 1; | ||
@@ -1058,3 +1063,6 @@ for ( | ||
); | ||
_bottomMaxIndex = index; | ||
if (position !== null) targetIndices[position] = index; | ||
} else { | ||
break; | ||
} | ||
@@ -1075,34 +1083,79 @@ | ||
let negativeStartIndex = visibleStartIndex - 3; | ||
let positiveStartIndex = visibleEndIndex + 3; | ||
let topOffset = indexToOffsetMap[Math.max(_topMinIndex, 0)] || 0; | ||
let bottomOffset = indexToOffsetMap[Math.max(_bottomMaxIndex, 0)] || 0; | ||
targetIndices.forEach((targetIndex, index) => { | ||
const prevStateResult = this._stateResult as RecycleStateResult<ItemT>; | ||
// const prevStateResult = this._stateResult as RecycleStateResult<ItemT>; | ||
// targetIndex is null or undefined | ||
if (targetIndex == null) { | ||
if (prevStateResult?.recycleState) { | ||
const _result = prevStateResult.recycleState[index]; | ||
if (_result) { | ||
const { item, targetKey } = _result; | ||
// maybe item has been deleted | ||
if (item === this._data[this.getKeyIndex(targetKey)]) { | ||
const { targetIndex, offset: _offset } = _result; | ||
if (targetIndex < visibleStartIndex) { | ||
const offset = indexToOffsetMap[negativeStartIndex--]; | ||
if (typeof offset === 'number') | ||
recycleStateResult.push({ | ||
..._result, | ||
offset: offset || _offset, | ||
}); | ||
} else if (targetIndex > visibleStartIndex) { | ||
const offset = indexToOffsetMap[positiveStartIndex++]; | ||
if (typeof offset === 'number') | ||
recycleStateResult.push({ | ||
..._result, | ||
offset: offset || _offset, | ||
}); | ||
} | ||
// if (prevStateResult?.recycleState) { | ||
// const _result = prevStateResult.recycleState[index]; | ||
// if (_result) { | ||
// const { item, targetKey } = _result; | ||
// // maybe item has been deleted | ||
// if (item === this._data[this.getKeyIndex(targetKey)]) { | ||
// const { targetIndex, offset: _offset } = _result; | ||
// if (targetIndex < visibleStartIndex) { | ||
// const offset = indexToOffsetMap[negativeStartIndex--]; | ||
// if (typeof offset === 'number') | ||
// recycleStateResult.push({ | ||
// ..._result, | ||
// offset: offset || _offset, | ||
// }); | ||
// } else if (targetIndex > visibleStartIndex) { | ||
// const offset = indexToOffsetMap[positiveStartIndex++]; | ||
// if (typeof offset === 'number') | ||
// recycleStateResult.push({ | ||
// ..._result, | ||
// offset: offset || _offset, | ||
// }); | ||
// } | ||
// } | ||
// } | ||
// } | ||
// return; | ||
targetIndex = _targetIndices[index]; | ||
const item = data[targetIndex]; | ||
if (!item) return; | ||
const itemKey = this.getItemKey(item, targetIndex); | ||
const itemMeta = this.getItemMeta(item, targetIndex); | ||
const itemLayout = itemMeta?.getLayout(); | ||
const itemLength = | ||
(itemLayout?.height || 0) + (itemMeta?.getSeparatorLength() || 0); | ||
let offset = 0; | ||
if (this._scrollMetrics && itemLayout) { | ||
const velocity = this._scrollMetrics.velocity; | ||
// scroll up, preserve start | ||
if (velocity < 0) { | ||
topOffset -= itemLength; | ||
offset = topOffset; | ||
// scroll down, preserve end | ||
} else if (velocity > 0) { | ||
bottomOffset += itemLength; | ||
offset = bottomOffset; | ||
} else { | ||
if (targetIndex < visibleStartIndex) { | ||
topOffset -= itemLength; | ||
offset = topOffset; | ||
} else { | ||
bottomOffset += itemLength; | ||
offset = bottomOffset; | ||
} | ||
} | ||
} | ||
recycleStateResult.push({ | ||
key: `recycle_${index}`, | ||
targetKey: itemKey, | ||
targetIndex, | ||
length: itemLength, | ||
isSpace: false, | ||
isSticky: false, | ||
item, | ||
// 如果没有offset,说明item是新增的,那么它渲染就在最开始位置好了 | ||
offset: itemLayout ? offset : 0, | ||
position: 'buffered', | ||
}); | ||
return; | ||
@@ -1109,0 +1162,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
Sorry, the diff of this file is too big to display
1706168
20292