-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMockBookList.js
executable file
·99 lines (88 loc) · 1.84 KB
/
MockBookList.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import React, {
Component,
} from 'react';
import {
StyleSheet,
Text,
View,
Image,
ListView,
} from 'react-native';
import BookItem from './BookItem';
class BookList extends Component {
constructor(props) {
super(props);
var ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2
});
this.state = {
dataSource: ds.cloneWithRows([])
}
}
componentDidMount() {
this._refreshData();
}
_renderRow(rowData) {
return (<BookItem
coverURL={rowData.book_image}
title={rowData.title}
author={rowData.author}/>);
}
_refreshData() {
var books = [
{
rank: 1,
title: 'GATHERING PREY',
author: 'John Sandford',
book_image: 'http://du.ec2.nytimes.com.s3.amazonaws.com/prd/books/9780399168796.jpg'
},
{
rank: 2,
title: 'MEMORY MAN',
author: 'David Baldacci',
book_image: 'http://du.ec2.nytimes.com.s3.amazonaws.com/prd/books/9781455586387.jpg'
}
];
this.setState({
books: books,
dataSource: this.state.dataSource.cloneWithRows(books)
});
}
render() {
return (
<View style={styles.container}>
<ListView
dataSource={this.state.dataSource}
renderRow={this._renderRow}
contentContainerStyle={styles.listContent}
style={styles.list}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#FFFFFF',
paddingTop: 24
},
list: {
flex: 1,
flexDirection: 'row'
},
listContent: {
flex: 1,
flexDirection: 'column'
},
row: {
flex: 1,
fontSize: 24,
padding: 42,
borderWidth: 1,
borderColor: '#DDDDDD'
}
});
export default BookList;