我想在React Native中構建一個註釋部分,但我在正確處理文本溢出和省略號時遇到問題。React本機處理省略號當一行中的多個文本組件
理想的情況下,當用戶名是足夠長的時間,應當修剪和動作名稱應該所有的方式,直到達到像時間戳推向右側這樣的:
我就是用這個代碼最接近:
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>
這將產生以下結果:
搞清楚一個獨特的結構和樣式組將處理這兩種情況的任何幫助,將不勝感激。
謝謝!
作爲一個方面說明,我也有一箇中間版本,其中長的用戶名會起作用,但那麼短的一個會被打破,隨時保持「註釋」一路向右。 'author'上沒有'commentTitle'包裝器,'flex:1'和'numberOfLines = {1}'。 – fmoga