(fix): scroll state when resizing not being remebered
(fix): missing input box gaps
This commit is contained in:
parent
f96d84f95e
commit
c99b5940b8
2 changed files with 17 additions and 2 deletions
|
|
@ -87,7 +87,7 @@ export default function InputComponent({
|
||||||
<Card
|
<Card
|
||||||
ref={inputBoxRef}
|
ref={inputBoxRef}
|
||||||
className={cn(
|
className={cn(
|
||||||
"rounded-none border-b-0 pt-0 pb-[env(safe-area-inset-bottom)]",
|
"rounded-none border-b-0 pt-0 pb-[env(safe-area-inset-bottom)] mx-2",
|
||||||
isMobile
|
isMobile
|
||||||
? "border-0 border-t fixed w-full bottom-0 left-0 px-2"
|
? "border-0 border-t fixed w-full bottom-0 left-0 px-2"
|
||||||
: "rounded-t-xl",
|
: "rounded-t-xl",
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ export default function Screen() {
|
||||||
Record<number, number>
|
Record<number, number>
|
||||||
>({});
|
>({});
|
||||||
const measurementRefs = React.useRef(new Map<number, HTMLDivElement>());
|
const measurementRefs = React.useRef(new Map<number, HTMLDivElement>());
|
||||||
|
const shouldRestoreBottomOnResizeRef = React.useRef(false);
|
||||||
|
|
||||||
const hasValidChatUser = Number.isSafeInteger(userId) && userId > 0;
|
const hasValidChatUser = Number.isSafeInteger(userId) && userId > 0;
|
||||||
const hasSharedSecret = sharedSecret.length > 0;
|
const hasSharedSecret = sharedSecret.length > 0;
|
||||||
|
|
@ -225,8 +226,22 @@ export default function Screen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleResize = () => {
|
const handleResize = () => {
|
||||||
|
if (scrollRef.current) {
|
||||||
|
shouldRestoreBottomOnResizeRef.current =
|
||||||
|
getDistanceFromBottom(scrollRef.current) <= stickyBottomThreshold;
|
||||||
|
}
|
||||||
|
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
virtualizer.measure();
|
virtualizer.measure();
|
||||||
|
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
if (!scrollRef.current || !shouldRestoreBottomOnResizeRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
||||||
|
shouldRestoreBottomOnResizeRef.current = false;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -234,7 +249,7 @@ export default function Screen() {
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener("resize", handleResize);
|
window.removeEventListener("resize", handleResize);
|
||||||
};
|
};
|
||||||
}, [virtualizer]);
|
}, [stickyBottomThreshold, virtualizer]);
|
||||||
|
|
||||||
React.useLayoutEffect(() => {
|
React.useLayoutEffect(() => {
|
||||||
const element = inputBoxRef.current;
|
const element = inputBoxRef.current;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue