-
Notifications
You must be signed in to change notification settings - Fork 375
Expand file tree
/
Copy pathUnsupportedAttachment.tsx
More file actions
86 lines (76 loc) · 2.67 KB
/
UnsupportedAttachment.tsx
File metadata and controls
86 lines (76 loc) · 2.67 KB
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
import React, { useMemo } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import type { Attachment } from 'stream-chat';
import { FileIconProps } from './FileIcon';
import {
MessageContextValue,
useMessageContext,
} from '../../contexts/messageContext/MessageContext';
import {
MessagesContextValue,
useMessagesContext,
} from '../../contexts/messagesContext/MessagesContext';
import { useTheme } from '../../contexts/themeContext/ThemeContext';
import { useTranslationContext } from '../../contexts/translationContext/TranslationContext';
import { primitives } from '../../theme';
export type UnsupportedAttachmentProps = Partial<
Pick<MessagesContextValue, 'FileAttachmentIcon'> & Pick<MessageContextValue, 'isMyMessage'>
> & {
/** The attachment to render */
attachment: Attachment;
attachmentIconSize?: FileIconProps['size'];
};
export const UnsupportedAttachment = (props: UnsupportedAttachmentProps) => {
const { FileAttachmentIcon: FileAttachmentIconDefault } = useMessagesContext();
const { isMyMessage } = useMessageContext();
const { attachment, attachmentIconSize, FileAttachmentIcon = FileAttachmentIconDefault } = props;
const styles = useStyles({ isMyMessage });
const {
theme: {
messageItemView: {
unsupportedAttachment: { container, details, title },
},
},
} = useTheme();
const { t } = useTranslationContext();
return (
<View style={[styles.container, container]}>
<FileAttachmentIcon mimeType={attachment.mime_type} size={attachmentIconSize} />
<View style={[styles.details, details]}>
<Text numberOfLines={2} style={[styles.title, title]}>
{attachment.title ?? t('Unsupported Attachment')}
</Text>
</View>
</View>
);
};
UnsupportedAttachment.displayName = 'UnsupportedAttachment{messageItemView{file}}';
const useStyles = ({ isMyMessage }: { isMyMessage: boolean }) => {
const {
theme: { semantics },
} = useTheme();
return useMemo(() => {
return StyleSheet.create({
container: {
alignItems: 'center',
flexDirection: 'row',
padding: primitives.spacingSm,
gap: primitives.spacingSm,
width: 256, // TODO: Fix this
backgroundColor: isMyMessage
? semantics.chatBgAttachmentOutgoing
: semantics.chatBgAttachmentIncoming,
},
details: {
flexShrink: 1,
gap: primitives.spacingXxs,
},
title: {
color: semantics.textPrimary,
fontSize: primitives.typographyFontSizeSm,
fontWeight: primitives.typographyFontWeightSemiBold,
lineHeight: primitives.typographyLineHeightTight,
},
});
}, [semantics, isMyMessage]);
};