[NEW] Attachments improvements (#125)
* Support <http://link|Text> * Attachment title blank space
This commit is contained in:
parent
caf0f2354c
commit
1edce04840
|
@ -30,6 +30,11 @@ const styles = StyleSheet.create({
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
alignItems: 'center'
|
alignItems: 'center'
|
||||||
},
|
},
|
||||||
|
author: {
|
||||||
|
fontWeight: 'bold',
|
||||||
|
marginHorizontal: 5,
|
||||||
|
flex: 1
|
||||||
|
},
|
||||||
time: {
|
time: {
|
||||||
fontSize: 10,
|
fontSize: 10,
|
||||||
fontWeight: 'normal',
|
fontWeight: 'normal',
|
||||||
|
@ -57,6 +62,14 @@ const onPress = (attachment) => {
|
||||||
}
|
}
|
||||||
Linking.openURL(attachment.title_link || attachment.author_link);
|
Linking.openURL(attachment.title_link || attachment.author_link);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Support <http://link|Text>
|
||||||
|
const formatText = text =>
|
||||||
|
text.replace(
|
||||||
|
new RegExp('(?:<|<)((?:https|http):\\/\\/[^\\|]+)\\|(.+?)(?=>|>)(?:>|>)', 'gm'),
|
||||||
|
(match, url, title) => `[${ title }](${ url })`
|
||||||
|
);
|
||||||
|
|
||||||
const Reply = ({ attachment, timeFormat }) => {
|
const Reply = ({ attachment, timeFormat }) => {
|
||||||
if (!attachment) {
|
if (!attachment) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -68,7 +81,6 @@ const Reply = ({ attachment, timeFormat }) => {
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Avatar
|
<Avatar
|
||||||
style={{ marginLeft: 5 }}
|
|
||||||
text={attachment.author_name}
|
text={attachment.author_name}
|
||||||
size={16}
|
size={16}
|
||||||
avatar={attachment.author_icon}
|
avatar={attachment.author_icon}
|
||||||
|
@ -77,7 +89,7 @@ const Reply = ({ attachment, timeFormat }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderAuthor = () => (
|
const renderAuthor = () => (
|
||||||
attachment.author_name ? <Text style={{ fontWeight: 'bold' }}>{attachment.author_name}</Text> : null
|
attachment.author_name ? <Text style={styles.author}>{attachment.author_name}</Text> : null
|
||||||
);
|
);
|
||||||
|
|
||||||
const renderTime = () => {
|
const renderTime = () => {
|
||||||
|
@ -85,8 +97,21 @@ const Reply = ({ attachment, timeFormat }) => {
|
||||||
return time ? <Text style={styles.time}>{ time }</Text> : null;
|
return time ? <Text style={styles.time}>{ time }</Text> : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const renderTitle = () => {
|
||||||
|
if (!(attachment.author_icon || attachment.author_name || attachment.ts)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<View style={styles.authorContainer}>
|
||||||
|
{renderAvatar()}
|
||||||
|
{renderAuthor()}
|
||||||
|
{renderTime()}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const renderText = () => (
|
const renderText = () => (
|
||||||
attachment.text ? <Markdown msg={attachment.text} /> : null
|
attachment.text ? <Markdown msg={formatText(attachment.text)} /> : null
|
||||||
);
|
);
|
||||||
|
|
||||||
const renderFields = () => {
|
const renderFields = () => {
|
||||||
|
@ -113,11 +138,7 @@ const Reply = ({ attachment, timeFormat }) => {
|
||||||
>
|
>
|
||||||
<QuoteMark color={attachment.color} />
|
<QuoteMark color={attachment.color} />
|
||||||
<View style={styles.attachmentContainer}>
|
<View style={styles.attachmentContainer}>
|
||||||
<View style={styles.authorContainer}>
|
{renderTitle()}
|
||||||
<Text>
|
|
||||||
{renderAvatar()} {renderAuthor()} {renderTime()}
|
|
||||||
</Text>
|
|
||||||
</View>
|
|
||||||
{renderText()}
|
{renderText()}
|
||||||
{renderFields()}
|
{renderFields()}
|
||||||
{attachment.attachments.map(attach => <Reply key={attach.text} attachment={attach} timeFormat={timeFormat} />)}
|
{attachment.attachments.map(attach => <Reply key={attach.text} attachment={attach} timeFormat={timeFormat} />)}
|
||||||
|
|
Loading…
Reference in New Issue