1
1
import { FeedViewType } from "@follow/constants"
2
2
import { useWhoami } from "@follow/store/user/hooks"
3
3
import type { FlashList } from "@shopify/flash-list"
4
+ import type { RefObject } from "react"
4
5
import { useEffect } from "react"
5
6
6
7
import { useGeneralSettingKey } from "@/src/atoms/settings/general"
7
8
import { withErrorBoundary } from "@/src/components/common/ErrorBoundary"
8
9
import { NoLoginInfo } from "@/src/components/common/NoLoginInfo"
9
10
import { ListErrorView } from "@/src/components/errors/ListErrorView"
10
11
import { useRegisterNavigationScrollView } from "@/src/components/layouts/tabbar/hooks"
12
+ import { useNavigation } from "@/src/lib/navigation/hooks"
11
13
import { EntryListContentPicture } from "@/src/modules/entry-list/EntryListContentPicture"
14
+ import { EntryDetailScreen } from "@/src/screens/(stack)/entries/[entryId]/EntryDetailScreen"
12
15
13
16
import { useFetchEntriesControls } from "../screen/atoms"
14
17
import { EntryListContentArticle } from "./EntryListContentArticle"
@@ -69,6 +72,8 @@ function EntryListSelectorImpl({ entryIds, viewId, active = true }: EntryListSel
69
72
}
70
73
} , [ isRefetching , ref ] )
71
74
75
+ useAutoScrollToEntryAfterPullUpToNext ( ref , entryIds || [ ] )
76
+
72
77
return < ContentComponent ref = { ref } entryIds = { entryIds } active = { active } view = { viewId } />
73
78
}
74
79
@@ -82,3 +87,32 @@ export const EntryListSelector = withErrorBoundary(
82
87
} ,
83
88
ListErrorView ,
84
89
)
90
+
91
+ const useAutoScrollToEntryAfterPullUpToNext = (
92
+ ref : RefObject < FlashList < any > | null > ,
93
+ entryIds : string [ ] ,
94
+ ) => {
95
+ const navigation = useNavigation ( )
96
+ useEffect ( ( ) => {
97
+ return navigation . on ( "screenChange" , ( payload ) => {
98
+ if ( ! payload . route ) return
99
+ if ( payload . type !== "appear" ) return
100
+ if ( payload . route . Component !== EntryDetailScreen ) return
101
+ if ( payload . route . screenOptions ?. stackAnimation !== "fade_from_bottom" ) return
102
+ const nextEntryId =
103
+ payload . route . props &&
104
+ typeof payload . route . props === "object" &&
105
+ "entryId" in payload . route . props &&
106
+ typeof payload . route . props . entryId === "string"
107
+ ? payload . route . props . entryId
108
+ : undefined
109
+ const idx = nextEntryId ? ( entryIds ?. indexOf ( nextEntryId || "" ) ?? - 1 ) : - 1
110
+ if ( idx === - 1 ) return
111
+ ref ?. current ?. scrollToIndex ( {
112
+ index : idx ,
113
+ animated : false ,
114
+ viewOffset : 70 ,
115
+ } )
116
+ } )
117
+ } , [ entryIds , navigation , ref ] )
118
+ }
0 commit comments