import React from 'react'; import { View, Text, StyleSheet } from 'react-native'; import PropTypes from 'prop-types'; import FastImage from 'react-native-fast-image'; import Touchable from 'react-native-platform-touchable'; import isEqual from 'lodash/isEqual'; import openLink from '../../utils/openLink'; import sharedStyles from '../../views/Styles'; import { themes } from '../../constants/colors'; import { withTheme } from '../../theme'; import { withSplit } from '../../split'; const styles = StyleSheet.create({ button: { marginTop: 6 }, container: { flex: 1, flexDirection: 'column', borderRadius: 4, borderWidth: 1 }, textContainer: { flex: 1, flexDirection: 'column', padding: 15, justifyContent: 'flex-start', alignItems: 'flex-start' }, title: { fontSize: 16, ...sharedStyles.textMedium }, description: { fontSize: 16, ...sharedStyles.textRegular }, marginTop: { marginTop: 4 }, image: { width: '100%', height: 150, borderTopLeftRadius: 4, borderTopRightRadius: 4 } }); const UrlImage = React.memo(({ image, user, baseUrl }) => { if (!image) { return null; } image = image.includes('http') ? image : `${ baseUrl }/${ image }?rc_uid=${ user.id }&rc_token=${ user.token }`; return ; }, (prevProps, nextProps) => prevProps.image === nextProps.image); const UrlContent = React.memo(({ title, description, theme }) => ( {title ? {title} : null} {description ? {description} : null} ), (prevProps, nextProps) => { if (prevProps.title !== nextProps.title) { return false; } if (prevProps.description !== nextProps.description) { return false; } if (prevProps.theme !== nextProps.theme) { return false; } return true; }); const Url = React.memo(({ url, index, user, baseUrl, split, theme }) => { if (!url) { return null; } const onPress = () => openLink(url.url, theme); return ( 0 && styles.marginTop, styles.container, { backgroundColor: themes[theme].chatComponentBackground, borderColor: themes[theme].borderColor }, split && sharedStyles.tabletContent ]} background={Touchable.Ripple(themes[theme].bannerBackground)} > <> ); }, (oldProps, newProps) => isEqual(oldProps.url, newProps.url) && oldProps.split === newProps.split && oldProps.theme === newProps.theme); const Urls = React.memo(({ urls, user, baseUrl, split, theme }) => { if (!urls || urls.length === 0) { return null; } return urls.map((url, index) => ( )); }, (oldProps, newProps) => isEqual(oldProps.urls, newProps.urls) && oldProps.split === newProps.split && oldProps.theme === newProps.theme); UrlImage.propTypes = { image: PropTypes.string, user: PropTypes.object, baseUrl: PropTypes.string }; UrlImage.displayName = 'MessageUrlImage'; UrlContent.propTypes = { title: PropTypes.string, description: PropTypes.string, theme: PropTypes.string }; UrlContent.displayName = 'MessageUrlContent'; Url.propTypes = { url: PropTypes.object.isRequired, index: PropTypes.number, user: PropTypes.object, baseUrl: PropTypes.string, theme: PropTypes.string, split: PropTypes.bool }; Url.displayName = 'MessageUrl'; Urls.propTypes = { urls: PropTypes.array, user: PropTypes.object, baseUrl: PropTypes.string, theme: PropTypes.string, split: PropTypes.bool }; Urls.displayName = 'MessageUrls'; export default withTheme(withSplit(Urls));