Poll for new posts on app foreground (#2152)
parent
9c0c18d5d0
commit
102094b10a
|
@ -1,6 +1,7 @@
|
|||
import React, {memo, MutableRefObject} from 'react'
|
||||
import {
|
||||
ActivityIndicator,
|
||||
AppState,
|
||||
Dimensions,
|
||||
RefreshControl,
|
||||
StyleProp,
|
||||
|
@ -142,12 +143,23 @@ let Feed = ({
|
|||
}
|
||||
}, [enabled])
|
||||
React.useEffect(() => {
|
||||
if (!pollInterval) {
|
||||
return
|
||||
let cleanup1: () => void | undefined, cleanup2: () => void | undefined
|
||||
const subscription = AppState.addEventListener('change', nextAppState => {
|
||||
// check for new on app foreground
|
||||
if (nextAppState === 'active') {
|
||||
checkForNewRef.current?.()
|
||||
}
|
||||
})
|
||||
cleanup1 = () => subscription.remove()
|
||||
if (pollInterval) {
|
||||
// check for new on interval
|
||||
const i = setInterval(() => checkForNewRef.current?.(), pollInterval)
|
||||
return () => clearInterval(i)
|
||||
cleanup2 = () => clearInterval(i)
|
||||
}
|
||||
return () => {
|
||||
cleanup1?.()
|
||||
cleanup2?.()
|
||||
}
|
||||
}, [pollInterval])
|
||||
|
||||
const feedItems = React.useMemo(() => {
|
||||
|
|
Loading…
Reference in New Issue