Can now long press on markdown links (#648)

* Can now long press on markdown links

* Review feedback
This commit is contained in:
Chris Duarte 2017-06-19 11:51:13 -07:00 committed by Harrison Healey
parent a68d4f4579
commit 94c8cb1ff7
3 changed files with 31 additions and 5 deletions

View file

@ -30,7 +30,8 @@ export default class Markdown extends React.PureComponent {
textStyles: PropTypes.object,
blockStyles: PropTypes.object,
emojiSizes: PropTypes.object,
value: PropTypes.string.isRequired
value: PropTypes.string.isRequired,
onLongPress: PropTypes.func
};
static defaultProps = {
@ -57,7 +58,8 @@ export default class Markdown extends React.PureComponent {
text: 65
}
})
}
},
onLongPress: () => true
};
constructor(props) {
@ -75,7 +77,7 @@ export default class Markdown extends React.PureComponent {
emph: Renderer.forwardChildren,
strong: Renderer.forwardChildren,
code: this.renderCodeSpan,
link: MarkdownLink,
link: this.renderLink,
image: this.renderImage,
atMention: this.renderAtMention,
channelLink: this.renderChannelLink,
@ -259,6 +261,17 @@ export default class Markdown extends React.PureComponent {
return rendered;
}
renderLink = ({children, href}) => {
return (
<MarkdownLink
href={href}
onLongPress={this.props.onLongPress}
>
{children}
</MarkdownLink>
);
}
render() {
const ast = this.parser.parse(this.props.value);

View file

@ -10,9 +10,14 @@ import CustomPropTypes from 'app/constants/custom_prop_types';
export default class MarkdownLink extends PureComponent {
static propTypes = {
children: CustomPropTypes.Children.isRequired,
href: PropTypes.string.isRequired
href: PropTypes.string.isRequired,
onLongPress: PropTypes.func
};
static defaultProps = {
onLongPress: () => true
}
handlePress = () => {
const url = this.props.href.toLowerCase();
@ -24,6 +29,13 @@ export default class MarkdownLink extends PureComponent {
};
render() {
return <Text onPress={this.handlePress}>{this.props.children}</Text>;
return (
<Text
onPress={this.handlePress}
onLongPress={this.props.onLongPress}
>
{this.props.children}
</Text>
);
}
}

View file

@ -390,6 +390,7 @@ class Post extends PureComponent {
textStyles={textStyles}
blockStyles={blockStyles}
value={post.message}
onLongPress={this.showOptionsContext}
/>
</View>
</View>