Skip to content

Commit 7ce726e

Browse files
committed
use thread typing events on SampleApp ThreadScreen
1 parent 6f518ca commit 7ce726e

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

examples/SampleApp/src/screens/ThreadScreen.tsx

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ import {
66
Thread,
77
useAttachmentPickerContext,
88
useTheme,
9+
ThreadContextValue,
10+
useTypingString,
911
} from 'stream-chat-react-native';
1012

1113
import { ScreenHeader } from '../components/ScreenHeader';
1214

1315
import type { RouteProp } from '@react-navigation/native';
1416

17+
import type { Channel as StreamChatChannel } from 'stream-chat';
18+
1519
import type {
1620
LocalAttachmentType,
1721
LocalChannelType,
@@ -34,6 +38,31 @@ type ThreadScreenRouteProp = RouteProp<StackNavigatorParamList, 'ThreadScreen'>;
3438
type ThreadScreenProps = {
3539
route: ThreadScreenRouteProp;
3640
};
41+
42+
export type ThreadHeaderProps = {
43+
thread: ThreadContextValue<
44+
LocalAttachmentType,
45+
LocalChannelType,
46+
LocalCommandType,
47+
LocalEventType,
48+
LocalMessageType,
49+
LocalReactionType,
50+
LocalUserType
51+
>['thread'];
52+
};
53+
54+
const ThreadHeader: React.FC<ThreadHeaderProps> = ({ thread }) => {
55+
const typing = useTypingString();
56+
57+
return (
58+
<ScreenHeader
59+
inSafeArea
60+
titleText='Thread Reply'
61+
subtitleText={typing ? typing : `with ${thread?.user?.name}`}
62+
/>
63+
);
64+
};
65+
3766
export const ThreadScreen: React.FC<ThreadScreenProps> = ({
3867
route: {
3968
params: { channel, thread },
@@ -51,6 +80,11 @@ export const ThreadScreen: React.FC<ThreadScreenProps> = ({
5180
return () => setSelectedImages([]);
5281
}, []);
5382

83+
useEffect(() => {
84+
setSelectedImages([]);
85+
return () => setSelectedImages([]);
86+
}, []);
87+
5488
return (
5589
<SafeAreaView style={[styles.container, { backgroundColor: white }]}>
5690
<Channel<
@@ -68,11 +102,7 @@ export const ThreadScreen: React.FC<ThreadScreenProps> = ({
68102
thread={thread}
69103
>
70104
<View style={styles.container}>
71-
<ScreenHeader
72-
inSafeArea
73-
subtitleText={`with ${thread?.user?.name}`}
74-
titleText='Thread Reply'
75-
/>
105+
<ThreadHeader thread={thread} />
76106
<Thread<
77107
LocalAttachmentType,
78108
LocalChannelType,

0 commit comments

Comments
 (0)