2019-09-03 19:27:57 +00:00
|
|
|
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';
|
2019-09-03 19:27:57 +00:00
|
|
|
import openLink from '../../utils/openLink';
|
|
|
|
|
|
|
|
const Link = React.memo(({
|
2019-12-11 23:01:12 +00:00
|
|
|
children, link, preview, theme
|
2019-09-03 19:27:57 +00:00
|
|
|
}) => {
|
|
|
|
const handlePress = () => {
|
|
|
|
if (!link) {
|
|
|
|
return;
|
|
|
|
}
|
2019-12-11 23:01:12 +00:00
|
|
|
openLink(link, theme);
|
2019-09-03 19:27:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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-07 20:56:30 +00:00
|
|
|
onPress={preview ? undefined : handlePress}
|
2019-12-11 23:01:12 +00:00
|
|
|
style={
|
|
|
|
!preview
|
|
|
|
? { ...styles.link, color: themes[theme].actionTintColor }
|
2020-01-29 20:20:36 +00:00
|
|
|
: { color: themes[theme].bodyText }
|
2019-12-11 23:01:12 +00:00
|
|
|
}
|
2019-09-03 19:27:57 +00:00
|
|
|
>
|
|
|
|
{ childLength !== 0 ? children : link }
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
Link.propTypes = {
|
|
|
|
children: PropTypes.node,
|
2019-10-07 20:56:30 +00:00
|
|
|
link: PropTypes.string,
|
2019-12-11 23:01:12 +00:00
|
|
|
theme: PropTypes.string,
|
2019-10-07 20:56:30 +00:00
|
|
|
preview: PropTypes.bool
|
2019-09-03 19:27:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Link;
|