Skip to content

Commit

Permalink
fix: RWD not working
Browse files Browse the repository at this point in the history
  • Loading branch information
wellyshen committed May 30, 2021
1 parent f993b88 commit 97882ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-lamps-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-cool-virtual": patch
---

fix: RWD not working
13 changes: 5 additions & 8 deletions src/useVirtual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,13 @@ export default <

const measureItems = useCallback(
(useCache = true) => {
for (let i = 0; i < itemCount; i += 1) {
for (let i = 0; i < itemCount; i += 1)
msDataRef.current[i] = getMeasure(
i,
useCache && msDataRef.current[i]
? msDataRef.current[i].size
: getItemSize(i)
);
}
},
[getItemSize, getMeasure, itemCount]
);
Expand Down Expand Up @@ -442,19 +441,17 @@ export default <
outerRef,
(rect) => {
const isSameWidth = outerRectRef.current.width === rect.width;
const { current: prevMsData } = msDataRef;
const prevTotalSize =
msDataRef.current[msDataRef.current.length - 1]?.end || 0;

outerRectRef.current = rect;
measureItems(false);
handleScroll(scrollOffsetRef.current);

if (onResizeRef.current) onResizeRef.current(rect);

const { current: msData } = msDataRef;
const ratio =
!isSameWidth &&
prevMsData.length &&
msData[msData.length - 1].end / prevMsData[prevMsData.length - 1].end;
const totalSize = msDataRef.current[msDataRef.current.length - 1].end;
const ratio = !isSameWidth && totalSize / prevTotalSize;

if (ratio) scrollTo(scrollOffsetRef.current * ratio);
},
Expand Down

0 comments on commit 97882ac

Please sign in to comment.