This commit is contained in:
Zhiyuan Zheng 2021-03-24 23:46:07 +01:00
parent b07db55573
commit 3727f0e252
No known key found for this signature in database
GPG Key ID: 078A93AB607D85E0
2 changed files with 10 additions and 3 deletions

View File

@ -128,6 +128,7 @@ const Timeline: React.FC<Props> = ({
return ( return (
<> <>
<TimelineRefresh <TimelineRefresh
flRef={flRef}
queryKey={queryKey} queryKey={queryKey}
scrollY={scrollY} scrollY={scrollY}
fetchingType={fetchingType} fetchingType={fetchingType}

View File

@ -7,9 +7,9 @@ import {
} from '@utils/queryHooks/timeline' } from '@utils/queryHooks/timeline'
import { StyleConstants } from '@utils/styles/constants' import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager' import { useTheme } from '@utils/styles/ThemeManager'
import React, { useCallback, useRef, useState } from 'react' import React, { RefObject, useCallback, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { Platform, StyleSheet, Text, View } from 'react-native' import { FlatList, Platform, StyleSheet, Text, View } from 'react-native'
import { Circle } from 'react-native-animated-spinkit' import { Circle } from 'react-native-animated-spinkit'
import Animated, { import Animated, {
Extrapolate, Extrapolate,
@ -23,6 +23,7 @@ import Animated, {
import { InfiniteData, useQueryClient } from 'react-query' import { InfiniteData, useQueryClient } from 'react-query'
export interface Props { export interface Props {
flRef: RefObject<FlatList<any>>
queryKey: QueryKeyTimeline queryKey: QueryKeyTimeline
scrollY: Animated.SharedValue<number> scrollY: Animated.SharedValue<number>
fetchingType: Animated.SharedValue<0 | 1 | 2> fetchingType: Animated.SharedValue<0 | 1 | 2>
@ -40,6 +41,7 @@ export const SEPARATION_Y_2 = -(
) )
const TimelineRefresh: React.FC<Props> = ({ const TimelineRefresh: React.FC<Props> = ({
flRef,
queryKey, queryKey,
scrollY, scrollY,
fetchingType, fetchingType,
@ -137,6 +139,10 @@ const TimelineRefresh: React.FC<Props> = ({
} }
) )
} }
const callRefetch = async () => {
await refetch()
setTimeout(() => flRef.current?.scrollToOffset({ offset: 1 }), 50)
}
const [textRight, setTextRight] = useState(0) const [textRight, setTextRight] = useState(0)
const arrowY = useAnimatedStyle(() => ({ const arrowY = useAnimatedStyle(() => ({
@ -225,7 +231,7 @@ const TimelineRefresh: React.FC<Props> = ({
break break
case 2: case 2:
runOnJS(prepareRefetch)() runOnJS(prepareRefetch)()
runOnJS(refetch)() runOnJS(callRefetch)()
break break
} }
}, },