mattermost-mobile/app/components/markdown/markdown_link.js
Chris Duarte 94c8cb1ff7 Can now long press on markdown links (#648)
* Can now long press on markdown links

* Review feedback
2017-06-19 14:51:13 -04:00

41 lines
1 KiB
JavaScript

// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {Linking, Text} from 'react-native';
import CustomPropTypes from 'app/constants/custom_prop_types';
export default class MarkdownLink extends PureComponent {
static propTypes = {
children: CustomPropTypes.Children.isRequired,
href: PropTypes.string.isRequired,
onLongPress: PropTypes.func
};
static defaultProps = {
onLongPress: () => true
}
handlePress = () => {
const url = this.props.href.toLowerCase();
Linking.canOpenURL(url).then((supported) => {
if (supported) {
Linking.openURL(url);
}
});
};
render() {
return (
<Text
onPress={this.handlePress}
onLongPress={this.props.onLongPress}
>
{this.props.children}
</Text>
);
}
}