From c1ebde8fe9a278f33967abb22ed9d50c35c1b507 Mon Sep 17 00:00:00 2001 From: xmflsct Date: Tue, 7 Feb 2023 23:38:34 +0100 Subject: [PATCH] Fix #699 --- src/components/Timeline/index.tsx | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/components/Timeline/index.tsx b/src/components/Timeline/index.tsx index 48da5cfe..9319852c 100644 --- a/src/components/Timeline/index.tsx +++ b/src/components/Timeline/index.tsx @@ -60,6 +60,9 @@ const Timeline: React.FC = ({ const { colors, theme } = useTheme() const { t } = useTranslation('componentTimeline') + const firstLoad = useSharedValue(!readMarker || disableRefresh) + const shouldAutoFetch = useSharedValue(!!readMarker && !disableRefresh) + const { data, refetch, isFetching, isLoading, isRefetching, fetchNextPage, isFetchingNextPage } = useTimelineQuery({ ...queryKey[1], @@ -68,7 +71,13 @@ const Timeline: React.FC = ({ notifyOnChangeProps: Platform.select({ ios: ['dataUpdatedAt', 'isFetching'], android: ['dataUpdatedAt', 'isFetching', 'isLoading'] - }) + }), + onSuccess: () => { + if (!firstLoad.value) { + firstLoad.value = true + fetchingType.value = 1 + } + } } }) @@ -90,6 +99,9 @@ const Timeline: React.FC = ({ (curr, prev) => { if (curr !== null && prev === null) { notifiedFetchedNotice.value = false + if (curr === 0) { + shouldAutoFetch.value = false + } } }, [fetchedCount] @@ -122,6 +134,15 @@ const Timeline: React.FC = ({ { onScroll: ({ contentOffset: { y } }) => { scrollY.value = y + if ( + y < 300 && + !isFetchingPrev.value && + fetchingType.value === 0 && + shouldAutoFetch.value && + Platform.OS === 'ios' + ) { + fetchingType.value = 1 + } }, onEndDrag: ({ contentOffset: { y } }) => { if (!disableRefresh && !isFetching) { @@ -129,6 +150,7 @@ const Timeline: React.FC = ({ fetchingType.value = 2 } else if (y <= SEPARATION_Y_1) { fetchingType.value = 1 + shouldAutoFetch.value = true } } }