Message List: Fix scroll animation after window resize

This commit is contained in:
Alexander Zinchuk 2021-05-12 03:13:20 +03:00
parent b96643ea2a
commit 37ce132cce
2 changed files with 8 additions and 5 deletions

View File

@ -52,6 +52,7 @@ import resetScroll from '../../util/resetScroll';
import fastSmoothScroll, { isAnimatingScroll } from '../../util/fastSmoothScroll';
import renderText from '../common/helpers/renderText';
import useLang, { LangFn } from '../../hooks/useLang';
import useWindowSize from '../../hooks/useWindowSize';
import Loading from '../ui/Loading';
import MessageScroll from './MessageScroll';
@ -328,9 +329,11 @@ const MessageList: FC<OwnProps & StateProps & DispatchProps> = ({
};
}, []);
useLayoutEffect(() => {
// Memorize height for scroll animation
const { height: windowHeight } = useWindowSize();
useEffect(() => {
containerRef.current!.dataset.normalHeight = String(containerRef.current!.offsetHeight);
}, []);
}, [windowHeight]);
// Workaround for an iOS bug when animated stickers sometimes disappear
useLayoutEffect(() => {

View File

@ -5,7 +5,7 @@ import { IDimensions } from '../modules/helpers';
import { throttle } from '../util/schedulers';
import windowSize from '../util/windowSize';
const RESIZE_TIMEOUT_MS = 250;
const THROTTLE = 250;
export default () => {
const [size, setSize] = useState<IDimensions>(windowSize.get());
@ -13,14 +13,14 @@ export default () => {
useEffect(() => {
const handleResize = throttle(() => {
setSize(windowSize.get());
}, RESIZE_TIMEOUT_MS, false);
}, THROTTLE, false);
window.addEventListener('resize', handleResize);
return () => {
window.removeEventListener('resize', handleResize);
};
});
}, []);
return size;
};