From a76746d3c7a8d39dcd207e291fcc1525b023c463 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 22 Dec 2023 21:57:05 +0000 Subject: [PATCH] Better positioning --- src/view/com/post-thread/PostThread.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/view/com/post-thread/PostThread.tsx b/src/view/com/post-thread/PostThread.tsx index 17fe89f6b8..3951dffbb4 100644 --- a/src/view/com/post-thread/PostThread.tsx +++ b/src/view/com/post-thread/PostThread.tsx @@ -139,7 +139,7 @@ function PostThreadLoaded({ const {hasSession} = useSession() const {_} = useLingui() const pal = usePalette('default') - const {isTablet, isDesktop} = useWebMediaQueries() + const {isTablet, isDesktop, isTabletOrMobile} = useWebMediaQueries() const ref = useRef(null) const highlightedPostRef = useRef(null) const needsScrollAdjustment = useRef( @@ -198,9 +198,15 @@ function PostThreadLoaded({ // wait for loading to finish if (thread.type === 'post' && !!thread.parent) { function onMeasure(pageY) { + let spinnerHeight = 0 + if (isDesktop) { + spinnerHeight = 40 + } else if (isTabletOrMobile) { + spinnerHeight = 82 + } ref.current?.scrollToOffset({ animated: false, - offset: pageY - (isDesktop ? 0 : 50), + offset: pageY - spinnerHeight, }) } if (isNative) { @@ -210,13 +216,12 @@ function PostThreadLoaded({ }, ) } else { - const pageY = - highlightedPostRef.current.getBoundingClientRect().top + scrollY + const pageY = highlightedPostRef.current.getBoundingClientRect().top onMeasure(pageY) } needsScrollAdjustment.current = false } - }, [thread, isDesktop]) + }, [thread, isDesktop, isTabletOrMobile]) const onPTR = React.useCallback(async () => { setIsPTRing(true)