2019-08-27 12:25:38 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Text } from 'react-native';
|
|
|
|
|
|
|
|
import styles from './styles';
|
|
|
|
import openLink from '../../utils/openLink';
|
|
|
|
|
|
|
|
const Link = React.memo(({
|
2019-10-04 13:28:36 +00:00
|
|
|
children, link, preview
|
2019-08-27 12:25:38 +00:00
|
|
|
}) => {
|
|
|
|
const handlePress = () => {
|
|
|
|
if (!link) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
openLink(link);
|
|
|
|
};
|
|
|
|
|
|
|
|
const childLength = React.Children.toArray(children).filter(o => o).length;
|
|
|
|
|
|
|
|
// if you have a [](https://rocket.chat) render https://rocket.chat
|
|
|
|
return (
|
|
|
|
<Text
|
2019-10-04 13:28:36 +00:00
|
|
|
onPress={preview ? undefined : handlePress}
|
2019-08-27 12:25:38 +00:00
|
|
|
style={styles.link}
|
|
|
|
>
|
|
|
|
{ childLength !== 0 ? children : link }
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
Link.propTypes = {
|
|
|
|
children: PropTypes.node,
|
2019-10-04 13:28:36 +00:00
|
|
|
link: PropTypes.string,
|
|
|
|
preview: PropTypes.bool
|
2019-08-27 12:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Link;
|