@infinite-list/data-model
Advanced tools
Comparing version 0.2.45-recycle-group.39 to 0.2.45-recycle-group.40
@@ -112,2 +112,11 @@ import Batchinator from '@x-oasis/batchinator'; | ||
}; | ||
resolveSiblingOffset(props: { | ||
startIndex: number; | ||
step: number; | ||
max: number; | ||
itemLength: number; | ||
offsetMap: { | ||
[key: number]: number; | ||
}; | ||
}): number; | ||
resolveRecycleItemLayout(info: any, indexToOffsetMap: any): { | ||
@@ -114,0 +123,0 @@ offset: any; |
{ | ||
"name": "@infinite-list/data-model", | ||
"version": "0.2.45-recycle-group.39", | ||
"version": "0.2.45-recycle-group.40", | ||
"files": [ | ||
@@ -5,0 +5,0 @@ "dist", |
@@ -644,2 +644,36 @@ import noop from '@x-oasis/noop'; | ||
resolveSiblingOffset(props: { | ||
startIndex: number; | ||
step: number; | ||
max: number; | ||
itemLength: number; | ||
offsetMap: { | ||
[key: number]: number; | ||
}; | ||
}) { | ||
const { startIndex, step = -1, max = 1, offsetMap, itemLength } = props; | ||
let siblingLength = 0; | ||
for (let idx = 0; idx < max; idx++) { | ||
const index = startIndex + step * idx; | ||
const meta = this.getFinalIndexItemMeta(index); | ||
const layout = meta?.getLayout(); | ||
const length = (layout?.height || 0) + (meta?.getSeparatorLength() || 0); | ||
if (meta && !meta?.isApproximateLayout) { | ||
const offset = | ||
offsetMap[index] != null | ||
? offsetMap[index] | ||
: this.getFinalIndexKeyOffset(index) || 0; | ||
return ( | ||
offset + | ||
siblingLength * (step > 0 ? -1 : 1) + | ||
length * (step > 0 ? 0 : 1) - | ||
itemLength * (step > 0 ? 1 : 0) | ||
); | ||
} | ||
siblingLength += length; | ||
} | ||
return this.itemOffsetBeforeLayoutReady; | ||
} | ||
resolveRecycleItemLayout(info, indexToOffsetMap) { | ||
@@ -661,38 +695,21 @@ const { meta: itemMeta, targetIndex } = info; | ||
const prevIndex = targetIndex - 1; | ||
const prevMeta = this.getFinalIndexItemMeta(prevIndex); | ||
if (!prevMeta?.isApproximateLayout) { | ||
const prevOffset = | ||
indexToOffsetMap[prevIndex] != null | ||
? indexToOffsetMap[prevIndex] | ||
: this.getFinalIndexKeyOffset(prevIndex) || 0; | ||
const prevLayout = prevMeta?.getLayout(); | ||
const prevLength = | ||
(prevLayout?.height || 0) + (prevMeta?.getSeparatorLength() || 0); | ||
let offset = this.resolveSiblingOffset({ | ||
itemLength, | ||
offsetMap: indexToOffsetMap, | ||
startIndex: targetIndex - 1, | ||
step: -1, | ||
max: 3, | ||
}); | ||
return { | ||
offset: prevOffset + prevLength, | ||
length: itemLength, | ||
}; | ||
if (offset === this.itemOffsetBeforeLayoutReady) { | ||
offset = this.resolveSiblingOffset({ | ||
itemLength, | ||
offsetMap: indexToOffsetMap, | ||
startIndex: targetIndex + 1, | ||
step: 1, | ||
max: 3, | ||
}); | ||
} | ||
const nextIndex = targetIndex + 1; | ||
const nextMeta = this.getFinalIndexItemMeta(nextIndex); | ||
if (!nextMeta?.isApproximateLayout) { | ||
const nextOffset = | ||
indexToOffsetMap[nextIndex] != null | ||
? indexToOffsetMap[nextIndex] | ||
: this.getFinalIndexKeyOffset(nextIndex) || 0; | ||
return { | ||
offset: nextOffset - itemLength, | ||
length: itemLength, | ||
}; | ||
} | ||
return { | ||
length: itemLength, | ||
offset: this.itemOffsetBeforeLayoutReady, | ||
}; | ||
return { offset, length: itemLength }; | ||
} | ||
@@ -699,0 +716,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
2658808
34594