【发布时间】:2016-07-13 09:46:27
【问题描述】:
我正在尝试在 React Native 中构建一个 cmets 部分,但我无法正确处理文本溢出和省略号。
理想情况下,当用户名足够长时,它应该被修剪,并且动作名称应该一直推到右边,直到它达到这样的时间戳:
我得到的最接近的是使用此代码:
const styles = StyleSheet.create({
commentRow: {
padding: 10
},
commentTopRow: {
flexDirection: 'row',
alignItems: 'center'
},
commentTitle: {
flex: 1
},
author: {
fontWeight: '500'
},
commentBody: {
paddingTop: 5,
paddingBottom: 5
}
});
<View style={styles.commentRow}>
<View style={styles.commentTopRow}>
<Text style={styles.commentTitle} numberOfLines={1}>
<Text style={styles.author}>User Name</Text>
<Text style={styles.action}> commented</Text>
</Text>
<Text style={styles.timestamp}>8h</Text>
</View>
<Text style={styles.commentBody}>comment body</Text>
</View>
产生以下结果:
任何帮助找出可以处理这两种情况的独特结构和样式集将不胜感激。
谢谢!
【问题讨论】:
-
作为旁注,我还有一个中间版本,其中长用户名可以使用,但短用户名被破坏,始终将“评论”固定在右侧。这没有
commentTitle包装器,flex: 1和numberOfLines={1}设置在author上。
标签: layout react-native flexbox ellipsis