aboutsummaryrefslogtreecommitdiff
path: root/src/screens/chat/ChatScreen.tsx
blob: a7dd37174ac2ee1f86fdd2a82b222c26cd7f3fe5 (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import {useBottomTabBarHeight} from '@react-navigation/bottom-tabs';
import {StackNavigationProp} from '@react-navigation/stack';
import React, {Fragment, useContext} from 'react';
import {StyleSheet, View} from 'react-native';
import {TouchableOpacity} from 'react-native-gesture-handler';
import {SafeAreaView} from 'react-native-safe-area-context';
import {
  Channel,
  Chat,
  MessageInput,
  MessageList,
  OverlayProvider,
  useMessageInputContext,
} from 'stream-chat-react-native';
import {ChatContext} from '../../App';
import UpArrowIcon from '../../assets/icons/up_arrow.svg';
import {ChatInput} from '../../components';
import ChatHeader from '../../components/messages/ChatHeader';
import {TAGG_LIGHT_BLUE} from '../../constants';
import {MainStackParams} from '../../routes';
import {ScreenType} from '../../types';
import {isIPhoneX} from '../../utils';

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 tabbarHeight = useBottomTabBarHeight();

  const chatTheme = {
    messageList: {
      container: {
        backgroundColor: 'white',
      },
    },
  };

  return (
    <SafeAreaView
      style={[
        styles.container,
        // unable to figure out the padding issue, a hacky solution
        {paddingBottom: isIPhoneX() ? tabbarHeight + 20 : tabbarHeight + 50},
      ]}>
      <ChatHeader screenType={ScreenType.Chat} />
      <Chat client={chatClient} style={chatTheme}>
        <OverlayProvider topInset={0} bottomInset={0}>
          <Channel
            channel={channel}
            keyboardVerticalOffset={0}
            OverlayReactionList={Fragment}
            messageActions={({copyMessage, deleteMessage}) => [
              copyMessage,
              deleteMessage,
            ]}>
            <MessageList onThreadSelect={() => {}} />
            <MessageInput />
          </Channel>
        </OverlayProvider>
      </Chat>
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  container: {
    backgroundColor: 'white',
    flex: 1,
  },

  submitButton: {
    height: 35,
    width: 35,
    backgroundColor: TAGG_LIGHT_BLUE,
    borderRadius: 999,
    justifyContent: 'center',
    alignItems: 'center',
    bottom: -5,
    alignSelf: 'flex-end',
  },
});

export default ChatScreen;