-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeed.js
More file actions
73 lines (61 loc) · 1.9 KB
/
Feed.js
File metadata and controls
73 lines (61 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import React, {Component} from 'react';
import {Image, ListView, Text, TouchableHighlight, View} from 'react-native';
import Toolbar from './Toolbar';
class Feed extends Component {
constructor(props) {
super(props);
const ds = new ListView.DataSource({rowHasChanged: (oldRow, newRow) => oldRow != newRow});
this.state = {
dataSource: ds.cloneWithRows([])
}
}
componentDidMount(){
let url = 'https://newsapi.org/v1/articles?source=techcrunch&apiKey=e50cce73ffff4ee98a9ef215b0fcd1ed';
fetch(url)
.then((response) => response.json())
.then((rjson) => {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(rjson.articles)
})
})
}
renderRow(article){
return(
<TouchableHighlight underlayColor={'transparent'} onPress={() => {this.props.navigator.push({name: 'article', article: article})}}>
<View style={styles.article}>
<Image style={styles.articleImage} source={{uri: article.urlToImage}}/>
<Text style={styles.articleTitle}>{article.title}</Text>
</View>
</TouchableHighlight>
)
}
render() {
return (
<View>
<Toolbar title="React Native Feed"/>
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow.bind(this)}
enableEmptySections={true}
/>
</View>
);
}
}
const styles = {
article: {
padding: 10,
borderBottomWidth: .5,
borderBottomColor: '#ccc',
flexDirection: 'row'
},
articleImage: {
width: 40,
height: 40
},
articleTitle: {
flex: 1,
marginLeft: 10
}
};
module.exports = Feed;