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

Commit

Permalink
use numberOfLines to limit str length
Browse files Browse the repository at this point in the history
  • Loading branch information
soliury committed May 6, 2016
1 parent 6a138f2 commit 8cd4fac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 38 deletions.
42 changes: 15 additions & 27 deletions src/components/MessageList.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ class MessageList extends Component {

_renderRow(message) {
var topic = message.topic;
var title = topic.title;
var titleLength = Math.floor((width - 100) / 15) + 2;
if (title.length > titleLength) {
title = title.substring(0, titleLength - 3) + '...';
}


return (
Expand All @@ -99,17 +94,14 @@ class MessageList extends Component {
underlayColor='#3498DB'
key={message.id}>
<View style={styles.row}>
<View style={styles.imgWrapper}>
<Image
style={styles.img}
source={{uri: parseImgUrl(message.author.avatar_url)}}
>
</Image>
</View>

<View style={[styles.topic]}>
<Text style={[styles.title]}>
{title}
<Image
style={styles.img}
source={{uri: parseImgUrl(message.author.avatar_url)}}
/>

<View style={styles.topic}>
<Text numberOfLines={1} style={[styles.title]}>
{topic.title}
</Text>

<View style={[styles.topicFooter]}>
Expand Down Expand Up @@ -171,24 +163,20 @@ const styles = StyleSheet.create({
"borderBottomColor": "rgba(0, 0, 0, 0.02)",
"borderBottomWidth": 1,
"paddingTop": 25,
"paddingRight": 0,
"paddingRight": 20,
"paddingBottom": 25,
"paddingLeft": 20
},
"imgWrapper": {
"width": 90,
"position": "absolute",
"left": 20,
"top": 25,
"height": 65
"paddingLeft": 20,
alignItems: 'center'
},
"img": {
"height": 40,
"width": 40,
"borderRadius": 20
"borderRadius": 20,
marginRight: 20
},
"topic": {
"marginLeft": 60
flexDirection: 'column',
width: width - 20 * 3 - 40
},
"title": {
"fontSize": 15
Expand Down
14 changes: 3 additions & 11 deletions src/components/TopicRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, {
Dimensions,
PropTypes
} from 'react-native';
import { parseImgUrl, strlen, substring } from '../utils';
import { parseImgUrl } from '../utils';


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


subStr(title) {
const titleLength = Math.floor((width - 100) / 15) * 2;
if (strlen(title) > titleLength) {
return substring(title, 0, titleLength - 3) + '...';
}
return title
}


render() {
const { topic } = this.props;

Expand All @@ -58,8 +49,9 @@ class TopicRow extends Component {
<View style={[styles.topic]}>
<Text
ref={view => this.titleText=view}
numberOfLines={1}
style={[styles.title]}>
{ this.subStr(topic.title) }
{ topic.title }
</Text>

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

0 comments on commit 8cd4fac

Please sign in to comment.