Skip to content

Commit df5ccc2

Browse files
Rohit3523diegolmelloOtavioStasiak
authored
feat: Display base64 image preview (RocketChat#5965)
Co-authored-by: Diego Mello <diegolmello@gmail.com> Co-authored-by: OtavioStasiak <otaviostasiakmusic@outlook.com>
1 parent bb65223 commit df5ccc2

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

app/containers/message/Components/Attachments/Attachments.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const Attachments: React.FC<IMessageAttachments> = React.memo(
3333
isReply={isReply}
3434
author={author}
3535
msg={msg}
36+
imagePreview={file.image_preview}
37+
imageType={file.image_type}
3638
/>
3739
);
3840
}

app/containers/message/Components/Attachments/Image/Container.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ const ImageContainer = ({
1616
style,
1717
isReply,
1818
author,
19-
msg
19+
msg,
20+
imagePreview,
21+
imageType
2022
}: IImageContainer): React.ReactElement | null => {
2123
const { user } = useContext(MessageContext);
2224
const { status, onPress, url, isEncrypted } = useMediaAutoDownload({ file, author, showAttachment });
2325

2426
const image = (
2527
<Button onPress={onPress}>
2628
<WidthAwareView>
27-
<MessageImage uri={url} status={status} encrypted={isEncrypted} />
29+
<MessageImage uri={url} status={status} encrypted={isEncrypted} imagePreview={imagePreview} imageType={imageType} />
2830
</WidthAwareView>
2931
</Button>
3032
);

app/containers/message/Components/Attachments/Image/Image.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import OverlayComponent from '../../OverlayComponent';
99
import { IMessageImage } from './definitions';
1010
import { WidthAwareContext } from '../../WidthAwareView';
1111

12-
export const MessageImage = React.memo(({ uri, status, encrypted = false }: IMessageImage) => {
12+
export const MessageImage = React.memo(({ uri, status, encrypted = false, imagePreview, imageType }: IMessageImage) => {
1313
const { colors } = useTheme();
1414
const [imageDimensions, setImageDimensions] = useState({ width: 0, height: 0 });
1515
const maxSize = useContext(WidthAwareContext);
@@ -48,7 +48,7 @@ export const MessageImage = React.memo(({ uri, status, encrypted = false }: IMes
4848
return (
4949
<>
5050
<View style={styles.image} />
51-
<OverlayComponent loading={false} style={styles.image} iconName='encrypted' />
51+
<OverlayComponent loading={false} style={styles.image} iconName='encrypted' showBackground={true} />
5252
</>
5353
);
5454
}
@@ -59,15 +59,21 @@ export const MessageImage = React.memo(({ uri, status, encrypted = false }: IMes
5959
<View style={[containerStyle, borderStyle]}>
6060
<ExpoImage style={imageStyle} source={{ uri: encodeURI(uri) }} contentFit='cover' />
6161
</View>
62-
) : (
63-
<View style={[styles.image, borderStyle]} />
64-
)}
62+
) : null}
6563
{['loading', 'to-download'].includes(status) || (status === 'downloaded' && !showImage) ? (
66-
<OverlayComponent
67-
loading={['loading', 'downloaded'].includes(status)}
68-
style={[styles.image, borderStyle]}
69-
iconName='arrow-down-circle'
70-
/>
64+
<>
65+
{imagePreview && imageType && !encrypted ? (
66+
<ExpoImage style={styles.image} source={{ uri: `data:${imageType};base64,${imagePreview}` }} contentFit='cover' />
67+
) : (
68+
<View style={[styles.image, borderStyle]} />
69+
)}
70+
<OverlayComponent
71+
loading={['loading', 'downloaded'].includes(status)}
72+
style={[styles.image, borderStyle]}
73+
iconName={status === 'to-download' ? 'arrow-down-circle' : 'loading'}
74+
showBackground={!imagePreview || !imageType}
75+
/>
76+
</>
7177
) : null}
7278
</>
7379
);

app/containers/message/Components/Attachments/Image/definitions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ export interface IImageContainer {
1212
getCustomEmoji?: TGetCustomEmoji;
1313
author?: IUserMessage;
1414
msg?: string;
15+
imagePreview?: string;
16+
imageType?: string;
1517
}
1618

1719
export interface IMessageImage {
1820
uri: string;
1921
status: TDownloadState;
2022
encrypted: boolean;
23+
imagePreview?: string;
24+
imageType?: string;
2125
}

app/containers/message/Components/OverlayComponent/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ import { CustomIcon, TIconsName } from '../../../CustomIcon';
99
const OverlayComponent = ({
1010
loading = false,
1111
style = {},
12-
iconName
12+
iconName,
13+
showBackground = true
1314
}: {
1415
loading: boolean;
1516
style: StyleProp<ViewStyle>;
1617
iconName: TIconsName;
18+
showBackground?: boolean;
1719
}) => {
1820
const { colors } = useTheme();
1921

2022
return (
2123
<>
22-
<View style={[style, styles.blurView, { backgroundColor: colors.surfaceNeutral }]} />
24+
{showBackground ? <View style={[style, styles.blurView, { backgroundColor: colors.surfaceNeutral }]} /> : null}
2325
<View style={[style, styles.blurIndicator]}>
2426
{loading ? <RCActivityIndicator size={54} /> : <CustomIcon name={iconName} size={54} />}
2527
</View>

0 commit comments

Comments
 (0)