diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-08-04 13:48:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-04 13:48:07 -0700 |
commit | f63ed57e3b0019c26a730150e1733370d44baaa9 (patch) | |
tree | d0d7aafe3537890f68469c9d08ae552f4b42deaa /src | |
parent | 5d2d0976ba5518c29ac2fc3692e0f68f075258c3 (diff) | |
download | voidsky-f63ed57e3b0019c26a730150e1733370d44baaa9.tar.zst |
Fix repeated firing of scroll into view on large threads (#1108)
Diffstat (limited to 'src')
-rw-r--r-- | src/view/com/post-thread/PostThread.tsx | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/view/com/post-thread/PostThread.tsx b/src/view/com/post-thread/PostThread.tsx index e7282cf83..399e47006 100644 --- a/src/view/com/post-thread/PostThread.tsx +++ b/src/view/com/post-thread/PostThread.tsx @@ -63,6 +63,7 @@ export const PostThread = observer(function PostThread({ }) { const pal = usePalette('default') const ref = useRef<FlatList>(null) + const hasScrolledIntoView = useRef<boolean>(false) const [isRefreshing, setIsRefreshing] = React.useState(false) const navigation = useNavigation<NavigationProp>() const posts = React.useMemo(() => { @@ -102,14 +103,36 @@ export const PostThread = observer(function PostThread({ }, [view, setIsRefreshing]) const onContentSizeChange = React.useCallback(() => { + // only run once + if (hasScrolledIntoView.current) { + return + } + + // wait for loading to finish + if ( + !view.hasContent || + (view.isFromCache && view.isLoadingFromCache) || + view.isLoading + ) { + return + } + const index = posts.findIndex(post => post._isHighlightedPost) if (index !== -1) { ref.current?.scrollToIndex({ index, animated: false, + viewPosition: 0, }) + hasScrolledIntoView.current = true } - }, [posts, ref]) + }, [ + posts, + view.hasContent, + view.isFromCache, + view.isLoadingFromCache, + view.isLoading, + ]) const onScrollToIndexFailed = React.useCallback( (info: { index: number @@ -279,7 +302,9 @@ export const PostThread = observer(function PostThread({ data={posts} initialNumToRender={posts.length} maintainVisibleContentPosition={ - view.isFromCache ? MAINTAIN_VISIBLE_CONTENT_POSITION : undefined + isIOS && view.isFromCache + ? MAINTAIN_VISIBLE_CONTENT_POSITION + : undefined } keyExtractor={item => item._reactKey} renderItem={renderItem} @@ -292,7 +317,7 @@ export const PostThread = observer(function PostThread({ /> } onContentSizeChange={ - !isIOS || !view.isFromCache ? onContentSizeChange : undefined + isIOS && view.isFromCache ? undefined : onContentSizeChange } onScrollToIndexFailed={onScrollToIndexFailed} style={s.hContentRegion} |