Skip to content

Commit 1618cca

Browse files
committed
fix: use useAppStateListener hook and move it to src level
1 parent 331a7da commit 1618cca

File tree

6 files changed

+6
-9
lines changed

6 files changed

+6
-9
lines changed

β€Žpackage/src/components/Channel/Channel.tsxβ€Ž

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { PropsWithChildren, useCallback, useEffect, useState } from 'react';
2-
import { AppState, KeyboardAvoidingViewProps, StyleSheet, Text, View } from 'react-native';
2+
import { KeyboardAvoidingViewProps, StyleSheet, Text, View } from 'react-native';
33
import {
44
ChannelState,
55
Channel as ChannelType,
@@ -13,6 +13,7 @@ import {
1313
Message as StreamMessage,
1414
} from 'stream-chat';
1515

16+
import { useAppStateListener } from '../../hooks/useAppStateListener';
1617
import { useCreateChannelContext } from './hooks/useCreateChannelContext';
1718
import { useCreateInputMessageInputContext } from './hooks/useCreateInputMessageInputContext';
1819
import { useCreateMessagesContext } from './hooks/useCreateMessagesContext';
@@ -690,12 +691,7 @@ const ChannelWithContext = <
690691
[thread?.id, channelId],
691692
);
692693

693-
useEffect(() => {
694-
AppState.addEventListener('change', handleAppBackground);
695-
return () => {
696-
AppState.removeEventListener('change', handleAppBackground);
697-
};
698-
}, [handleAppBackground]);
694+
useAppStateListener(undefined, handleAppBackground);
699695

700696
const handleEvent: EventHandler<At, Ch, Co, Ev, Me, Re, Us> = (event) => {
701697
if (thread) {

β€Žpackage/src/components/Chat/hooks/useIsOnline.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState } from 'react';
22

3-
import { useAppStateListener } from './useAppStateListener';
3+
import { useAppStateListener } from '../../../hooks/useAppStateListener';
44
import { NetInfo } from '../../../native';
55

66
import type { NetInfoSubscription } from '@react-native-community/netinfo';

β€Žpackage/src/components/index.tsβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export * from './ChannelPreview/hooks/useChannelPreviewDisplayPresence';
7070
export * from './ChannelPreview/hooks/useLatestMessagePreview';
7171

7272
export * from './Chat/Chat';
73-
export * from './Chat/hooks/useAppStateListener';
7473
export * from './Chat/hooks/useCreateChatContext';
7574
export * from './Chat/hooks/useIsOnline';
7675
export * from './Chat/hooks/useMutedUsers';

β€Žpackage/src/hooks/index.tsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './useAppStateListener';

β€Žpackage/src/index.tsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './components';
2+
export * from './hooks';
23
export { registerNativeHandlers, NetInfo } from './native';
34
export * from './contexts';
45
export * from './emoji-data/compiled';

0 commit comments

Comments
Β (0)