1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
import {useBottomTabBarHeight} from '@react-navigation/bottom-tabs';
import {StackNavigationProp, useHeaderHeight} from '@react-navigation/stack';
import React, {useContext} from 'react';
import {StyleSheet, View} from 'react-native';
import {useSelector} from 'react-redux';
import {
Channel,
Chat,
MessageInput,
MessageList,
} from 'stream-chat-react-native';
import {ChatContext} from '../../App';
import {MainStackParams} from '../../routes';
import {RootState} from '../../store/rootReducer';
type ChatScreenNavigationProp = StackNavigationProp<MainStackParams, 'Chat'>;
interface ChatScreenProps {
navigation: ChatScreenNavigationProp;
}
/*
* Screen that displays all of the user's active conversations.
*/
const ChatScreen: React.FC<ChatScreenProps> = () => {
const {channel, chatClient} = useContext(ChatContext);
const headerHeight = useHeaderHeight();
const tabbarHeight = useBottomTabBarHeight();
const {userId: loggedInUserId} = useSelector(
(state: RootState) => state.user.user,
);
const otherMembers = channel
? Object.values(channel.state.members).filter(
(member) => member.user?.id !== loggedInUserId,
)
: [];
const member = otherMembers.length === 1 ? otherMembers[0] : undefined;
return (
<View style={[styles.container, {paddingBottom: tabbarHeight}]}>
<Chat client={chatClient}>
<Channel channel={channel} keyboardVerticalOffset={headerHeight}>
<MessageList onThreadSelect={() => {}} />
<MessageInput />
</Channel>
</Chat>
</View>
);
};
const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
},
});
export default ChatScreen;
|