diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/components/messages/ChannelPreview.tsx | 112 |
1 files changed, 78 insertions, 34 deletions
diff --git a/src/components/messages/ChannelPreview.tsx b/src/components/messages/ChannelPreview.tsx index 8bd3a745..6b166b55 100644 --- a/src/components/messages/ChannelPreview.tsx +++ b/src/components/messages/ChannelPreview.tsx @@ -1,10 +1,15 @@ import {useNavigation} from '@react-navigation/core'; import React, {useContext} from 'react'; import {Image, StyleSheet, Text, View} from 'react-native'; -import {TouchableOpacity} from 'react-native-gesture-handler'; +import { + RectButton, + Swipeable, + TouchableOpacity, +} from 'react-native-gesture-handler'; import {useStore} from 'react-redux'; import {ChannelPreviewMessengerProps} from 'stream-chat-react-native'; import {ChatContext} from '../../App'; +import Trash from '../../assets/ionicons/trash-outline.svg'; import {TAGG_LIGHT_BLUE_2} from '../../constants'; import { LocalAttachmentType, @@ -38,39 +43,59 @@ const ChannelPreview: React.FC< const unread = channel.state.unreadCount > 0; return ( - <TouchableOpacity - style={styles.container} - onPress={() => { - setChannel(channel); - navigation.navigate('Chat'); - }}> - <View> - <Image - style={styles.avatar} - source={ - member - ? {uri: member.user?.thumbnail_url} - : require('../../assets/images/avatar-placeholder.png') - } - /> - {online && <View style={styles.online} />} - </View> - <View style={styles.content}> - <Text - style={[styles.name, unread ? styles.unread : {}]} - numberOfLines={1}> - {member?.user?.first_name} {member?.user?.last_name} - </Text> - <Text - style={[styles.lastMessage, unread ? styles.unread : {}]} - numberOfLines={1}> - {channel.state.messages.length > 0 - ? channel.state.messages[channel.state.messages.length - 1].text - : ''} - </Text> - </View> - {unread && <View style={styles.purpleDot} />} - </TouchableOpacity> + <Swipeable + overshootLeft={false} + overshootRight={false} + renderRightActions={() => ( + <View style={styles.swipeableContainer}> + <RectButton + style={styles.rightSwipeableButton} + onPress={() => { + channel.delete(); + }}> + <Trash + width={normalize(25)} + height={normalize(25)} + color={'white'} + /> + <Text style={styles.actionText}>Delete</Text> + </RectButton> + </View> + )}> + <TouchableOpacity + style={styles.container} + onPress={() => { + setChannel(channel); + navigation.navigate('Chat'); + }}> + <View> + <Image + style={styles.avatar} + source={ + member + ? {uri: member.user?.thumbnail_url} + : require('../../assets/images/avatar-placeholder.png') + } + /> + {online && <View style={styles.online} />} + </View> + <View style={styles.content}> + <Text + style={[styles.name, unread ? styles.unread : {}]} + numberOfLines={1}> + {member?.user?.first_name} {member?.user?.last_name} + </Text> + <Text + style={[styles.lastMessage, unread ? styles.unread : {}]} + numberOfLines={1}> + {channel.state.messages.length > 0 + ? channel.state.messages[channel.state.messages.length - 1].text + : ''} + </Text> + </View> + {unread && <View style={styles.purpleDot} />} + </TouchableOpacity> + </Swipeable> ); }; @@ -128,6 +153,25 @@ const styles = StyleSheet.create({ borderRadius: normalize(10) / 2, marginLeft: '5%', }, + swipeableContainer: { + alignItems: 'center', + justifyContent: 'center', + backgroundColor: '#C42634', + }, + rightSwipeableButton: { + width: 72, + height: 62, + justifyContent: 'center', + alignItems: 'center', + }, + actionText: { + color: 'white', + fontSize: normalize(12), + fontWeight: '500', + backgroundColor: 'transparent', + paddingHorizontal: '5%', + marginTop: '5%', + }, }); export default ChannelPreview; |