diff options
author | Eric Bailey <git@esb.lol> | 2023-11-27 09:43:05 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-27 09:43:05 -0600 |
commit | 828e53d53316b539b21a02cf252ccd5ff0c3e413 (patch) | |
tree | 6d9f7351045367992bf7231b51e1d16f3f8ac751 /src | |
parent | 0079030244092aaef4a40c37e457ef693f19e593 (diff) | |
download | voidsky-828e53d53316b539b21a02cf252ccd5ff0c3e413.tar.zst |
Fix soft reset scroll on profile (#1998)
Diffstat (limited to 'src')
-rw-r--r-- | src/view/screens/Profile.tsx | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/src/view/screens/Profile.tsx b/src/view/screens/Profile.tsx index 8282b2105..c3bc598a0 100644 --- a/src/view/screens/Profile.tsx +++ b/src/view/screens/Profile.tsx @@ -5,7 +5,6 @@ import {AppBskyActorDefs, moderateProfile, ModerationOpts} from '@atproto/api' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' import {NativeStackScreenProps, CommonNavigatorParams} from 'lib/routes/types' -import {ViewSelectorHandle} from '../com/util/ViewSelector' import {CenteredView, FlatList} from '../com/util/Views' import {ScreenHider} from 'view/com/util/moderation/ScreenHider' import {Feed} from 'view/com/posts/Feed' @@ -131,7 +130,6 @@ function ProfileScreenLoaded({ const {screen, track} = useAnalytics() const [currentPage, setCurrentPage] = React.useState(0) const {_} = useLingui() - const viewSelectorRef = React.useRef<ViewSelectorHandle>(null) const setDrawerSwipeDisabled = useSetDrawerSwipeDisabled() const extraInfoQuery = useProfileExtraInfoQuery(profile.did) const postsSectionRef = React.useRef<SectionRef>(null) @@ -184,14 +182,33 @@ function ProfileScreenLoaded({ listsIndex = nextIndex++ } + const scrollSectionToTop = React.useCallback( + (index: number) => { + if (index === postsIndex) { + postsSectionRef.current?.scrollToTop() + } else if (index === repliesIndex) { + repliesSectionRef.current?.scrollToTop() + } else if (index === mediaIndex) { + mediaSectionRef.current?.scrollToTop() + } else if (index === likesIndex) { + likesSectionRef.current?.scrollToTop() + } else if (index === feedsIndex) { + feedsSectionRef.current?.scrollToTop() + } else if (index === listsIndex) { + listsSectionRef.current?.scrollToTop() + } + }, + [postsIndex, repliesIndex, mediaIndex, likesIndex, feedsIndex, listsIndex], + ) + useFocusEffect( React.useCallback(() => { setMinimalShellMode(false) screen('Profile') return listenSoftReset(() => { - viewSelectorRef.current?.scrollToTop() + scrollSectionToTop(currentPage) }) - }, [viewSelectorRef, setMinimalShellMode, screen]), + }, [setMinimalShellMode, screen, currentPage, scrollSectionToTop]), ) useFocusEffect( @@ -225,21 +242,9 @@ function ProfileScreenLoaded({ const onCurrentPageSelected = React.useCallback( (index: number) => { - if (index === postsIndex) { - postsSectionRef.current?.scrollToTop() - } else if (index === repliesIndex) { - repliesSectionRef.current?.scrollToTop() - } else if (index === mediaIndex) { - mediaSectionRef.current?.scrollToTop() - } else if (index === likesIndex) { - likesSectionRef.current?.scrollToTop() - } else if (index === feedsIndex) { - feedsSectionRef.current?.scrollToTop() - } else if (index === listsIndex) { - listsSectionRef.current?.scrollToTop() - } + scrollSectionToTop(index) }, - [postsIndex, repliesIndex, mediaIndex, likesIndex, feedsIndex, listsIndex], + [scrollSectionToTop], ) // rendering |