verdnatura-chat/app/containers/markdown/Link.js

44 lines
943 B
JavaScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import { Text } from 'react-native';
import styles from './styles';
2019-12-11 23:01:12 +00:00
import { themes } from '../../constants/colors';
import openLink from '../../utils/openLink';
const Link = React.memo(({
2019-12-11 23:01:12 +00:00
children, link, preview, theme
}) => {
const handlePress = () => {
if (!link) {
return;
}
2019-12-11 23:01:12 +00:00
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}
2019-12-11 23:01:12 +00:00
style={
!preview
? { ...styles.link, color: themes[theme].actionTintColor }
: { color: themes[theme].titleText }
}
>
{ childLength !== 0 ? children : link }
</Text>
);
});
Link.propTypes = {
children: PropTypes.node,
link: PropTypes.string,
2019-12-11 23:01:12 +00:00
theme: PropTypes.string,
preview: PropTypes.bool
};
export default Link;