Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Poll for new posts on app foreground (#2152)

authored by

Paul Frazee and committed by
GitHub
102094b1 9c0c18d5

+17 -5
+17 -5
src/view/com/posts/Feed.tsx
··· 1 1 import React, {memo, MutableRefObject} from 'react' 2 2 import { 3 3 ActivityIndicator, 4 + AppState, 4 5 Dimensions, 5 6 RefreshControl, 6 7 StyleProp, ··· 142 143 } 143 144 }, [enabled]) 144 145 React.useEffect(() => { 145 - if (!pollInterval) { 146 - return 146 + let cleanup1: () => void | undefined, cleanup2: () => void | undefined 147 + const subscription = AppState.addEventListener('change', nextAppState => { 148 + // check for new on app foreground 149 + if (nextAppState === 'active') { 150 + checkForNewRef.current?.() 151 + } 152 + }) 153 + cleanup1 = () => subscription.remove() 154 + if (pollInterval) { 155 + // check for new on interval 156 + const i = setInterval(() => checkForNewRef.current?.(), pollInterval) 157 + cleanup2 = () => clearInterval(i) 147 158 } 148 - // check for new on interval 149 - const i = setInterval(() => checkForNewRef.current?.(), pollInterval) 150 - return () => clearInterval(i) 159 + return () => { 160 + cleanup1?.() 161 + cleanup2?.() 162 + } 151 163 }, [pollInterval]) 152 164 153 165 const feedItems = React.useMemo(() => {