From f3972c44f7e94da1df5bc0c84ff8d0c06fc450b3 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 22 Dec 2023 20:41:07 +0000 Subject: [PATCH] Scroll to post --- src/view/com/post-thread/PostThread.tsx | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/view/com/post-thread/PostThread.tsx b/src/view/com/post-thread/PostThread.tsx index 6cd1f35519..17fe89f6b8 100644 --- a/src/view/com/post-thread/PostThread.tsx +++ b/src/view/com/post-thread/PostThread.tsx @@ -197,14 +197,23 @@ function PostThreadLoaded({ // wait for loading to finish if (thread.type === 'post' && !!thread.parent) { - highlightedPostRef.current?.measure( - (_x, _y, _width, _height, _pageX, pageY) => { - ref.current?.scrollToOffset({ - animated: false, - offset: pageY - (isDesktop ? 0 : 50), - }) - }, - ) + function onMeasure(pageY) { + ref.current?.scrollToOffset({ + animated: false, + offset: pageY - (isDesktop ? 0 : 50), + }) + } + if (isNative) { + highlightedPostRef.current?.measure( + (_x, _y, _width, _height, _pageX, pageY) => { + onMeasure(pageY) + }, + ) + } else { + const pageY = + highlightedPostRef.current.getBoundingClientRect().top + scrollY + onMeasure(pageY) + } needsScrollAdjustment.current = false } }, [thread, isDesktop])