2021-09-13 20:41:05 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { StyleSheet, View } from 'react-native';
|
|
|
|
import FastImage from '@rocket.chat/react-native-fast-image';
|
|
|
|
import { BLOCK_CONTEXT } from '@rocket.chat/ui-kit';
|
|
|
|
|
|
|
|
import ImageContainer from '../message/Image';
|
|
|
|
import Navigation from '../../lib/Navigation';
|
2022-03-16 19:07:49 +00:00
|
|
|
import { IThumb, IImage, IElement } from './interfaces';
|
2022-03-29 20:06:50 +00:00
|
|
|
import { IAttachment } from '../../definitions';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
image: {
|
|
|
|
borderRadius: 2
|
|
|
|
},
|
|
|
|
mediaContext: {
|
|
|
|
marginRight: 8
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-03-16 19:07:49 +00:00
|
|
|
const ThumbContext = (args: IThumb) => (
|
2021-09-13 20:41:05 +00:00
|
|
|
<View style={styles.mediaContext}>
|
|
|
|
<Thumb size={20} {...args} />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
|
|
|
|
export const Thumb = ({ element, size = 88 }: IThumb) => (
|
2022-03-16 19:07:49 +00:00
|
|
|
<FastImage style={[{ width: size, height: size }, styles.image]} source={{ uri: element?.imageUrl }} />
|
2021-09-13 20:41:05 +00:00
|
|
|
);
|
|
|
|
|
2022-03-29 20:06:50 +00:00
|
|
|
export const Media = ({ element }: IImage) => {
|
|
|
|
const showAttachment = (attachment: IAttachment) => Navigation.navigate('AttachmentView', { attachment });
|
2022-03-16 19:07:49 +00:00
|
|
|
const imageUrl = element?.imageUrl ?? '';
|
2022-03-29 20:06:50 +00:00
|
|
|
|
|
|
|
return <ImageContainer file={{ image_url: imageUrl }} imageUrl={imageUrl} showAttachment={showAttachment} />;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
|
|
|
|
2022-03-29 20:06:50 +00:00
|
|
|
const genericImage = (element: IElement, context?: number) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
switch (context) {
|
|
|
|
case BLOCK_CONTEXT.SECTION:
|
|
|
|
return <Thumb element={element} />;
|
|
|
|
case BLOCK_CONTEXT.CONTEXT:
|
|
|
|
return <ThumbContext element={element} />;
|
|
|
|
default:
|
2022-03-29 20:06:50 +00:00
|
|
|
return <Media element={element} />;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-29 20:06:50 +00:00
|
|
|
export const Image = ({ element, context }: IImage) => genericImage(element, context);
|