From add632081e98b1011addc91a1c9e8ef925299773 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Sun, 8 Jun 2025 16:39:46 -0500 Subject: [PATCH] Ok need to compute headerHeight every time --- src/screens/PostThread/index.tsx | 97 ++++++++++++++++---------------- 1 file changed, 48 insertions(+), 49 deletions(-) diff --git a/src/screens/PostThread/index.tsx b/src/screens/PostThread/index.tsx index a712d51dfa..6b3623ed51 100644 --- a/src/screens/PostThread/index.tsx +++ b/src/screens/PostThread/index.tsx @@ -100,7 +100,6 @@ export function Inner({uri}: {uri: string | undefined}) { const listRef = useRef(null) const anchorRef = useRef(null) const headerRef = useRef(null) - const headerHeight = useRef(0) /* * On a cold load, parents are not prepended until the anchor post has @@ -137,9 +136,11 @@ export function Inner({uri}: {uri: string | undefined}) { const onContentSizeChangeWebOnly = web(() => { const list = listRef.current const anchor = anchorRef.current as any as Element + const header = headerRef.current as any as Element - if (list && anchor && shouldHandleScroll.current) { + if (list && anchor && header && shouldHandleScroll.current) { const anchorOffsetTop = anchor.getBoundingClientRect().top + const headerHeight = header.getBoundingClientRect().height /* * `deferParents` is `true` on a cold load, and always reset to @@ -168,7 +169,7 @@ export function Inner({uri}: {uri: string | undefined}) { * back _up_ to the top of the screen. */ list.scrollToOffset({ - offset: anchorOffsetTop - headerHeight.current, + offset: anchorOffsetTop - headerHeight, }) /* @@ -217,6 +218,33 @@ export function Inner({uri}: {uri: string | undefined}) { } }) + const prepareForParamsUpdate = useCallback(() => { + setDeferParents(true) + setMaxParentCount(PARENT_CHUNK_SIZE) + setMaxChildrenCount(CHILDREN_CHUNK_SIZE) + // listRef.current?.scrollToOffset({ + // animated: false, + // offset: 0, + // }) + shouldHandleScroll.current = true + }, [setDeferParents, setMaxParentCount, setMaxChildrenCount]) + + const setSortWrapped = useCallback( + (sort: string) => { + prepareForParamsUpdate() + thread.actions.setSort(sort) + }, + [thread, prepareForParamsUpdate], + ) + + const setViewWrapped = useCallback( + (view: ThreadViewOption) => { + prepareForParamsUpdate() + thread.actions.setView(view) + }, + [thread, prepareForParamsUpdate], + ) + const onStartReached = () => { if (thread.state.isFetching) return // prevent any state mutations if we know we're done @@ -309,25 +337,27 @@ export function Inner({uri}: {uri: string | undefined}) { ) } else if (item.depth === 0) { return ( - setDeferParents(false)}> + <> + setDeferParents(false)} + /> - + ) } else { if (thread.state.view === 'tree') { @@ -395,40 +425,9 @@ export function Inner({uri}: {uri: string | undefined}) { [thread, optimisticOnPostReply, onReplyToAnchor, gtMobile], ) - const prepareForParamsUpdate = useCallback(() => { - setDeferParents(true) - setMaxParentCount(PARENT_CHUNK_SIZE) - setMaxChildrenCount(CHILDREN_CHUNK_SIZE) - listRef.current?.scrollToOffset({ - animated: false, - offset: 0, - }) - shouldHandleScroll.current = true - }, [setDeferParents, setMaxParentCount, setMaxChildrenCount]) - - const setSortWrapped = useCallback( - (sort: string) => { - prepareForParamsUpdate() - thread.actions.setSort(sort) - }, - [thread, prepareForParamsUpdate], - ) - - const setViewWrapped = useCallback( - (view: ThreadViewOption) => { - prepareForParamsUpdate() - thread.actions.setView(view) - }, - [thread, prepareForParamsUpdate], - ) - return ( <> - { - headerHeight.current = e.nativeEvent.layout.height - }}> +