Skip to content

Commit 0aff06e

Browse files
Merge pull request #12 from ShareChat/fix/window-height-issue
Fix: Auto adjust height logic
2 parents 079fc04 + 36e123a commit 0aff06e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/SwipeableWrapper/index.jsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const SwipeableWrapper = forwardRef(
5151
const index = useRef(initialIndex);
5252
const previousIndex = useRef(initialIndex);
5353
const totalWidth = useRef(0);
54+
const totalHeight = useRef(0);
5455
const rAF = useRaf();
5556

5657
const onRestFn = useCallback(() => {
@@ -62,8 +63,7 @@ const SwipeableWrapper = forwardRef(
6263
if (!disableAutoScroll) scrollToTop();
6364
const { current: el = null } = elementRef;
6465
if (el) {
65-
const height = window.innerHeight - el.clientTop;
66-
el.children[prevIndex].style.height = `${height}px`;
66+
el.children[prevIndex].style.height = `${totalHeight.current}px`;
6767
el.children[currIndex].style.height = "auto";
6868
}
6969
});
@@ -157,10 +157,11 @@ const SwipeableWrapper = forwardRef(
157157
el.parentElement.offsetWidth,
158158
window.innerWidth,
159159
);
160-
const height = window.innerHeight - el.clientTop;
160+
totalHeight.current =
161+
window.innerHeight - Math.max(el.offsetTop, el.clientTop);
161162
for (let i = 0; i < children.length; i += 1) {
162163
el.children[i].style.height =
163-
initialIndex === i ? "auto" : `${height}px`;
164+
initialIndex === i ? "auto" : `${totalHeight.current}px`;
164165
}
165166
}
166167
}, [children.length, initialIndex]);

0 commit comments

Comments
 (0)