Rocket.Chat.ReactNative/app/containers/markdown/Link.js

44 lines
942 B
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import { Text } from 'react-native';
import styles from './styles';
import { themes } from '../../constants/colors';
import openLink from '../../utils/openLink';
const Link = React.memo(({
children, link, preview, theme
}) => {
const handlePress = () => {
if (!link) {
return;
}
openLink(link, theme);
};
const childLength = React.Children.toArray(children).filter(o => o).length;
// if you have a [](https://rocket.chat) render https://rocket.chat
return (
<Text
onPress={preview ? undefined : handlePress}
style={
!preview
? { ...styles.link, color: themes[theme].actionTintColor }
: { color: themes[theme].bodyText }
}
>
{ childLength !== 0 ? children : link }
</Text>
);
});
Link.propTypes = {
children: PropTypes.node,
link: PropTypes.string,
theme: PropTypes.string,
preview: PropTypes.bool
};
export default Link;