Merge pull request #160 from lbryio/linkify-description
make links in file descriptions clickable
This commit is contained in:
commit
1820710f06
3 changed files with 45 additions and 10 deletions
|
@ -23,16 +23,18 @@ export default class Link extends React.PureComponent {
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
let styles = [];
|
let styles = [];
|
||||||
|
if (style) {
|
||||||
if (style.length) {
|
if (style.length) {
|
||||||
styles = styles.concat(style);
|
styles = styles.concat(style);
|
||||||
} else {
|
} else {
|
||||||
styles.push(style);
|
styles.push(style);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity onPress={onPress ? onPress : this.handlePress}>
|
<Text style={styles} onPress={onPress ? onPress : this.handlePress}>
|
||||||
<Text style={styles}>{text}</Text>
|
{text}
|
||||||
</TouchableOpacity>
|
</Text>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,6 +20,7 @@ import ChannelPage from '../channel';
|
||||||
import FileDownloadButton from '../../component/fileDownloadButton';
|
import FileDownloadButton from '../../component/fileDownloadButton';
|
||||||
import FileItemMedia from '../../component/fileItemMedia';
|
import FileItemMedia from '../../component/fileItemMedia';
|
||||||
import FilePrice from '../../component/filePrice';
|
import FilePrice from '../../component/filePrice';
|
||||||
|
import Link from '../../component/link';
|
||||||
import MediaPlayer from '../../component/mediaPlayer';
|
import MediaPlayer from '../../component/mediaPlayer';
|
||||||
import UriBar from '../../component/uriBar';
|
import UriBar from '../../component/uriBar';
|
||||||
import Video from 'react-native-video';
|
import Video from 'react-native-video';
|
||||||
|
@ -133,6 +134,34 @@ class FilePage extends React.PureComponent {
|
||||||
return 'file:///' + fileInfo.download_path;
|
return 'file:///' + fileInfo.download_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
linkify = (text) => {
|
||||||
|
let linkifiedContent = [];
|
||||||
|
let lines = text.split(/\n/g);
|
||||||
|
linkifiedContent = lines.map((line, i) => {
|
||||||
|
let tokens = line.split(/\s/g);
|
||||||
|
let lineContent = tokens.length === 0 ? '' : tokens.map((token, j) => {
|
||||||
|
let hasSpace = j !== (tokens.length - 1);
|
||||||
|
let maybeSpace = hasSpace ? ' ' : '';
|
||||||
|
|
||||||
|
if (token.match(/^(lbry|https?):\/\//g)) {
|
||||||
|
return (
|
||||||
|
<Link key={j}
|
||||||
|
style={filePageStyle.link}
|
||||||
|
href={token}
|
||||||
|
text={token} />
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return token + maybeSpace;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
lineContent.push("\n");
|
||||||
|
return (<Text key={i}>{lineContent}</Text>);
|
||||||
|
});
|
||||||
|
|
||||||
|
return linkifiedContent;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
claim,
|
claim,
|
||||||
|
@ -246,7 +275,7 @@ class FilePage extends React.PureComponent {
|
||||||
<ScrollView style={showActions ? filePageStyle.scrollContainerActions : filePageStyle.scrollContainer}>
|
<ScrollView style={showActions ? filePageStyle.scrollContainerActions : filePageStyle.scrollContainer}>
|
||||||
<Text style={filePageStyle.title} selectable={true}>{title}</Text>
|
<Text style={filePageStyle.title} selectable={true}>{title}</Text>
|
||||||
{channelName && <Text style={filePageStyle.channelName} selectable={true}>{channelName}</Text>}
|
{channelName && <Text style={filePageStyle.channelName} selectable={true}>{channelName}</Text>}
|
||||||
{description && <Text style={filePageStyle.description} selectable={true}>{description}</Text>}
|
{description && <Text style={filePageStyle.description} selectable={true}>{this.linkify(description)}</Text>}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -54,12 +54,13 @@ const filePageStyle = StyleSheet.create({
|
||||||
color: Colors.ChannelGrey
|
color: Colors.ChannelGrey
|
||||||
},
|
},
|
||||||
description: {
|
description: {
|
||||||
|
color: Colors.DescriptionGrey,
|
||||||
fontFamily: 'Metropolis-Regular',
|
fontFamily: 'Metropolis-Regular',
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
|
lineHeight: 20,
|
||||||
marginLeft: 20,
|
marginLeft: 20,
|
||||||
marginRight: 20,
|
marginRight: 20,
|
||||||
marginBottom: 40,
|
marginBottom: 40
|
||||||
color: Colors.DescriptionGrey
|
|
||||||
},
|
},
|
||||||
thumbnail: {
|
thumbnail: {
|
||||||
width: screenWidth,
|
width: screenWidth,
|
||||||
|
@ -156,6 +157,9 @@ const filePageStyle = StyleSheet.create({
|
||||||
top: 0,
|
top: 0,
|
||||||
bottom: 60,
|
bottom: 60,
|
||||||
zIndex: 100
|
zIndex: 100
|
||||||
|
},
|
||||||
|
link: {
|
||||||
|
color: Colors.LbryGreen
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue