Skip to content

Commit f6c916e

Browse files
committed
fix decimal
1 parent 0c5a205 commit f6c916e

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

examples/animate.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const MyItem: React.FC<MyItemProps> = (
5252
}}
5353
>
5454
{({ className, style }, motionRef) => (
55-
<div ref={motionRef} className={classNames('item', className)} style={style}>
55+
<div ref={motionRef} className={classNames('item', className)} style={style} data-id={id}>
5656
<div style={{ height: uuid % 2 ? 100 : undefined }}>
5757
<button
5858
onClick={() => {
@@ -119,6 +119,7 @@ const Demo = () => {
119119

120120
<List
121121
dataSource={dataSource}
122+
data-id="list"
122123
height={200}
123124
itemHeight={30}
124125
itemKey="id"

src/List.tsx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,25 @@ class List<T> extends React.Component<ListProps<T>, ListState> {
127127
getItemKey: this.getItemKey,
128128
});
129129

130+
// TODO: REMOVE ME
131+
const locatedItemRelativeTop = getItemRelativeTop({
132+
itemIndex,
133+
itemOffsetPtg,
134+
itemElementHeights: this.itemElementHeights,
135+
scrollPtg: getElementScrollPercentage(this.listRef.current),
136+
clientHeight: this.listRef.current.clientHeight,
137+
getItemKey: this.getItemKey,
138+
});
139+
console.warn('MEASURE:::', this.getItemKey(itemIndex), locatedItemRelativeTop);
140+
console.warn(
141+
' ->',
142+
itemIndex,
143+
itemOffsetPtg,
144+
this.itemElementHeights,
145+
getElementScrollPercentage(this.listRef.current),
146+
this.listRef.current.clientHeight,
147+
);
148+
130149
let startItemTop = locatedItemTop;
131150
for (let index = itemIndex - 1; index >= startIndex; index -= 1) {
132151
startItemTop -= this.itemElementHeights[this.getItemKey(index)] || 0;
@@ -145,14 +164,19 @@ class List<T> extends React.Component<ListProps<T>, ListState> {
145164
itemOffsetPtg: originItemOffsetPtg,
146165
startIndex: originStartIndex,
147166
endIndex: originEndIndex,
167+
scrollTop: originScrollTop,
148168
} = this.state;
149169

150170
// 1. Get origin located item top
151171
const originLocatedItemRelativeTop = getItemRelativeTop({
152172
itemIndex: originItemIndex,
153173
itemOffsetPtg: originItemOffsetPtg,
154174
itemElementHeights: this.itemElementHeights,
155-
scrollPtg: getElementScrollPercentage(this.listRef.current),
175+
scrollPtg: getScrollPercentage({
176+
scrollTop: originScrollTop,
177+
scrollHeight: prevProps.dataSource.length * itemHeight,
178+
clientHeight: this.listRef.current.clientHeight,
179+
}),
156180
clientHeight: this.listRef.current.clientHeight,
157181
getItemKey: (index: number) => this.getItemKey(index, prevProps),
158182
});
@@ -164,6 +188,18 @@ class List<T> extends React.Component<ListProps<T>, ListState> {
164188
this.getItemKey(originItemIndex, prevProps),
165189
originLocatedItemRelativeTop,
166190
);
191+
console.warn(
192+
' -> ',
193+
originItemIndex,
194+
originItemOffsetPtg,
195+
this.itemElementHeights,
196+
getScrollPercentage({
197+
scrollTop: originScrollTop,
198+
scrollHeight: prevProps.dataSource.length * itemHeight,
199+
clientHeight: this.listRef.current.clientHeight,
200+
}),
201+
this.listRef.current.clientHeight,
202+
);
167203

168204
// 2. Find the compare item
169205
const removedItemIndex: number = prevProps.dataSource.findIndex((_, index) => {

src/util.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export function getItemRelativeTop({
112112
const locatedItemHeight = itemElementHeights[getItemKey(itemIndex)] || 0;
113113
const locatedItemTop = scrollPtg * clientHeight;
114114
const locatedItemOffset = itemOffsetPtg * locatedItemHeight;
115+
console.error('GIRT:', locatedItemTop, scrollPtg, clientHeight);
115116
return locatedItemTop - locatedItemOffset;
116117
}
117118

0 commit comments

Comments
 (0)