Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit 8cd4fac

Browse files
author
soliury
committed
use numberOfLines to limit str length
1 parent 6a138f2 commit 8cd4fac

File tree

2 files changed

+18
-38
lines changed

2 files changed

+18
-38
lines changed

src/components/MessageList.js

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ class MessageList extends Component {
8686

8787
_renderRow(message) {
8888
var topic = message.topic;
89-
var title = topic.title;
90-
var titleLength = Math.floor((width - 100) / 15) + 2;
91-
if (title.length > titleLength) {
92-
title = title.substring(0, titleLength - 3) + '...';
93-
}
9489

9590

9691
return (
@@ -99,17 +94,14 @@ class MessageList extends Component {
9994
underlayColor='#3498DB'
10095
key={message.id}>
10196
<View style={styles.row}>
102-
<View style={styles.imgWrapper}>
103-
<Image
104-
style={styles.img}
105-
source={{uri: parseImgUrl(message.author.avatar_url)}}
106-
>
107-
</Image>
108-
</View>
109-
110-
<View style={[styles.topic]}>
111-
<Text style={[styles.title]}>
112-
{title}
97+
<Image
98+
style={styles.img}
99+
source={{uri: parseImgUrl(message.author.avatar_url)}}
100+
/>
101+
102+
<View style={styles.topic}>
103+
<Text numberOfLines={1} style={[styles.title]}>
104+
{topic.title}
113105
</Text>
114106

115107
<View style={[styles.topicFooter]}>
@@ -171,24 +163,20 @@ const styles = StyleSheet.create({
171163
"borderBottomColor": "rgba(0, 0, 0, 0.02)",
172164
"borderBottomWidth": 1,
173165
"paddingTop": 25,
174-
"paddingRight": 0,
166+
"paddingRight": 20,
175167
"paddingBottom": 25,
176-
"paddingLeft": 20
177-
},
178-
"imgWrapper": {
179-
"width": 90,
180-
"position": "absolute",
181-
"left": 20,
182-
"top": 25,
183-
"height": 65
168+
"paddingLeft": 20,
169+
alignItems: 'center'
184170
},
185171
"img": {
186172
"height": 40,
187173
"width": 40,
188-
"borderRadius": 20
174+
"borderRadius": 20,
175+
marginRight: 20
189176
},
190177
"topic": {
191-
"marginLeft": 60
178+
flexDirection: 'column',
179+
width: width - 20 * 3 - 40
192180
},
193181
"title": {
194182
"fontSize": 15

src/components/TopicRow.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import React, {
88
Dimensions,
99
PropTypes
1010
} from 'react-native';
11-
import { parseImgUrl, strlen, substring } from '../utils';
11+
import { parseImgUrl } from '../utils';
1212

1313

1414
const { width } = Dimensions.get('window');
@@ -27,15 +27,6 @@ class TopicRow extends Component {
2727
};
2828

2929

30-
subStr(title) {
31-
const titleLength = Math.floor((width - 100) / 15) * 2;
32-
if (strlen(title) > titleLength) {
33-
return substring(title, 0, titleLength - 3) + '...';
34-
}
35-
return title
36-
}
37-
38-
3930
render() {
4031
const { topic } = this.props;
4132

@@ -58,8 +49,9 @@ class TopicRow extends Component {
5849
<View style={[styles.topic]}>
5950
<Text
6051
ref={view => this.titleText=view}
52+
numberOfLines={1}
6153
style={[styles.title]}>
62-
{ this.subStr(topic.title) }
54+
{ topic.title }
6355
</Text>
6456

6557
<View style={[styles.topicFooter]}>

0 commit comments

Comments
 (0)