1
0
mirror of https://github.com/tooot-app/app synced 2025-01-31 02:37:13 +01:00
This commit is contained in:
xmflsct 2023-02-07 23:38:34 +01:00
parent 8775a0cb25
commit c1ebde8fe9

View File

@ -60,6 +60,9 @@ const Timeline: React.FC<Props> = ({
const { colors, theme } = useTheme() const { colors, theme } = useTheme()
const { t } = useTranslation('componentTimeline') const { t } = useTranslation('componentTimeline')
const firstLoad = useSharedValue<boolean>(!readMarker || disableRefresh)
const shouldAutoFetch = useSharedValue<boolean>(!!readMarker && !disableRefresh)
const { data, refetch, isFetching, isLoading, isRefetching, fetchNextPage, isFetchingNextPage } = const { data, refetch, isFetching, isLoading, isRefetching, fetchNextPage, isFetchingNextPage } =
useTimelineQuery({ useTimelineQuery({
...queryKey[1], ...queryKey[1],
@ -68,7 +71,13 @@ const Timeline: React.FC<Props> = ({
notifyOnChangeProps: Platform.select({ notifyOnChangeProps: Platform.select({
ios: ['dataUpdatedAt', 'isFetching'], ios: ['dataUpdatedAt', 'isFetching'],
android: ['dataUpdatedAt', 'isFetching', 'isLoading'] android: ['dataUpdatedAt', 'isFetching', 'isLoading']
}) }),
onSuccess: () => {
if (!firstLoad.value) {
firstLoad.value = true
fetchingType.value = 1
}
}
} }
}) })
@ -90,6 +99,9 @@ const Timeline: React.FC<Props> = ({
(curr, prev) => { (curr, prev) => {
if (curr !== null && prev === null) { if (curr !== null && prev === null) {
notifiedFetchedNotice.value = false notifiedFetchedNotice.value = false
if (curr === 0) {
shouldAutoFetch.value = false
}
} }
}, },
[fetchedCount] [fetchedCount]
@ -122,6 +134,15 @@ const Timeline: React.FC<Props> = ({
{ {
onScroll: ({ contentOffset: { y } }) => { onScroll: ({ contentOffset: { y } }) => {
scrollY.value = y scrollY.value = y
if (
y < 300 &&
!isFetchingPrev.value &&
fetchingType.value === 0 &&
shouldAutoFetch.value &&
Platform.OS === 'ios'
) {
fetchingType.value = 1
}
}, },
onEndDrag: ({ contentOffset: { y } }) => { onEndDrag: ({ contentOffset: { y } }) => {
if (!disableRefresh && !isFetching) { if (!disableRefresh && !isFetching) {
@ -129,6 +150,7 @@ const Timeline: React.FC<Props> = ({
fetchingType.value = 2 fetchingType.value = 2
} else if (y <= SEPARATION_Y_1) { } else if (y <= SEPARATION_Y_1) {
fetchingType.value = 1 fetchingType.value = 1
shouldAutoFetch.value = true
} }
} }
} }