import {useBottomTabBarHeight} from '@react-navigation/bottom-tabs'; import {StackNavigationProp} from '@react-navigation/stack'; import React, {useContext, useEffect} from 'react'; import {Image, StyleSheet, View} from 'react-native'; import {SafeAreaView, useSafeAreaInsets} from 'react-native-safe-area-context'; import {useStore} from 'react-redux'; import { Channel, Chat, DeepPartial, MessageInput, MessageList, useAttachmentPickerContext, Theme, useMessageContext, } from 'stream-chat-react-native'; import {ChatContext} from '../../App'; import {ChatHeader, ChatInput, TabsGradient} from '../../components'; import {MainStackParams} from '../../routes'; import {ScreenType} from '../../types'; import { getMember, HeaderHeight, isIPhoneX, normalize, SCREEN_WIDTH, } from '../../utils'; type ChatScreenNavigationProp = StackNavigationProp; interface ChatScreenProps { navigation: ChatScreenNavigationProp; } /* * Screen that displays all of the user's active conversations. */ const ChatScreen: React.FC = () => { const {channel, chatClient} = useContext(ChatContext); const tabbarHeight = useBottomTabBarHeight(); const {setTopInset} = useAttachmentPickerContext(); const insets = useSafeAreaInsets(); const state = useStore().getState(); const member = getMember(channel, state); const chatTheme: DeepPartial = { 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); }); const CustomTypingIndicator = () => { return ( ); }; const CustomMessageAvatar = () => { const message = useMessageContext(); return ( {message.lastGroupMessage === true && ( )} ); }; return ( null} messageActions={({copyMessage, deleteMessage}) => [ copyMessage, deleteMessage, ]} TypingIndicator={CustomTypingIndicator} myMessageTheme={loggedInUsersMessageTheme} MessageAvatar={CustomMessageAvatar}> {}} /> {/* */} ); }; const styles = StyleSheet.create({ container: { backgroundColor: 'white', flex: 1, }, typingIndicatorContainer: { backgroundColor: '#E4F0F2', width: 88, height: 32, borderRadius: 10, marginBottom: 10, marginLeft: SCREEN_WIDTH * 0.09, flexDirection: 'row', justifyContent: 'center', alignItems: 'center', }, messageAvatarContainer: { width: normalize(20), zIndex: 1, bottom: 20, marginRight: '2%', }, messageAvatar: { borderRadius: 50, width: normalize(18), height: normalize(18), }, }); export default ChatScreen;