aboutsummaryrefslogtreecommitdiff
path: root/src/screens/chat/ChatScreen.tsx
blob: 656c1c473cf5b5e26c95472edc62de56f9304408 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import {useBottomTabBarHeight} from '@react-navigation/bottom-tabs';
import {StackNavigationProp} from '@react-navigation/stack';
import React, {useContext, useEffect} from 'react';
import {StyleSheet} from 'react-native';
import {SafeAreaView, useSafeAreaInsets} from 'react-native-safe-area-context';
import {
  Channel,
  Chat,
  DeepPartial,
  MessageInput,
  MessageList,
  useAttachmentPickerContext,
  Theme,
} from 'stream-chat-react-native';
import {ChatContext} from '../../App';
import {
  ChatHeader,
  ChatInput,
  MessageAvatar,
  TabsGradient,
  TypingIndicator,
} from '../../components';
import {MainStackParams} from '../../routes';
import {ScreenType} from '../../types';
import {HeaderHeight, isIPhoneX, normalize, SCREEN_WIDTH} 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 {setTopInset} = useAttachmentPickerContext();
  const insets = useSafeAreaInsets();
  const chatTheme: DeepPartial<Theme> = {
    messageList: {
      container: {
        backgroundColor: 'white',
        width: SCREEN_WIDTH * 0.95,
        alignSelf: 'center',
      },
    },
    messageInput: {
      container: {
        backgroundColor: '#f8f8f8',
        height: 70,
      },
    },
    avatar: {
      container: {
        borderRadius: 10,
        width: normalize(18),
        height: normalize(18),
      },
    },
    messageSimple: {
      avatarWrapper: {
        container: {
          width: normalize(20),
          zIndex: 1,
          bottom: 20,
        },
      },
      container: {
        paddingTop: 8,
        flexDirection: 'row',
      },
      content: {
        metaContainer: {
          marginLeft: 5,
        },
        container: {},
        containerInner: {
          backgroundColor: '#E4F0F2',
          borderColor: 'transparent',
          borderBottomLeftRadius: 10,
          borderTopLeftRadius: 10,
          borderBottomRightRadius: 10,
          borderTopRightRadius: 10,
        },
      },
      status: {
        statusContainer: {},
      },
    },
  };

  const loggedInUsersMessageTheme = {
    messageSimple: {
      content: {
        containerInner: {
          backgroundColor: '#DEE6F4',
        },
        container: {
          left: 0,
        },
      },
    },
  };

  useEffect(() => {
    setTopInset(insets.top + HeaderHeight);
  });

  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}>
        <Channel
          channel={channel}
          keyboardVerticalOffset={0}
          OverlayReactionList={() => null}
          messageActions={({copyMessage, deleteMessage}) => [
            copyMessage,
            deleteMessage,
          ]}
          TypingIndicator={TypingIndicator}
          myMessageTheme={loggedInUsersMessageTheme}
          MessageAvatar={MessageAvatar}>
          <MessageList onThreadSelect={() => {}} />
          {/* <MessageInput /> */}
          <MessageInput Input={ChatInput} />
        </Channel>
      </Chat>
      <TabsGradient />
    </SafeAreaView>
  );
};

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

export default ChatScreen;