diff --git a/src/state/messages/index.tsx b/src/state/messages/index.tsx index e3485f642e..95ebf0afdd 100644 --- a/src/state/messages/index.tsx +++ b/src/state/messages/index.tsx @@ -1,7 +1,7 @@ import React, {useContext, useState, useSyncExternalStore} from 'react' import {AppState} from 'react-native' import {BskyAgent} from '@atproto-labs/api' -import {useFocusEffect} from '@react-navigation/native' +import {useFocusEffect, useIsFocused} from '@react-navigation/native' import {Convo, ConvoParams, ConvoState} from '#/state/messages/convo' import {useAgent} from '#/state/session' @@ -21,6 +21,7 @@ export function ChatProvider({ children, convoId, }: Pick & {children: React.ReactNode}) { + const isScreenFocused = useIsFocused() const {serviceUrl} = useDmServiceUrlStorage() const {getAgent} = useAgent() const [convo] = useState( @@ -47,10 +48,12 @@ export function ChatProvider({ React.useEffect(() => { const handleAppStateChange = (nextAppState: string) => { - if (nextAppState === 'active') { - convo.resume() - } else { - convo.background() + if (isScreenFocused) { + if (nextAppState === 'active') { + convo.resume() + } else { + convo.background() + } } } @@ -59,7 +62,7 @@ export function ChatProvider({ return () => { sub.remove() } - }, [convo]) + }, [convo, isScreenFocused]) return {children} }