-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathindex.ios.js
113 lines (105 loc) · 2.37 KB
/
index.ios.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
Image,
ListView,
} = React;
var ReactCBLite = require('react-native').NativeModules.ReactCBLite;
ReactCBLite.init(5984, 'admin', 'password');
var { manager } = require('react-native-couchbase-lite');
var ReactNativeCouchbaseLiteExample = React.createClass({
render: function () {
return (
<Home></Home>
);
}
});
var Home = React.createClass({
getInitialState() {
return {
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
})
}
},
componentDidMount() {
var database = new manager('http://admin:password@localhost:5984/', 'myapp');
database.createDatabase()
.then((res) => {
database.replicate('http://localhost:4984/moviesapp', 'myapp')
})
.then((res) => {
return database.getAllDocuments()
})
.then((res) => {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(res.rows)
});
console.log(res.rows)
})
.catch((ex) => {
console.log(ex)
})
},
render() {
return (
<View>
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderMovie}
style={styles.listView}/>
</View>
)
},
renderMovie(movie) {
var movie = movie.doc;
return (
<View style={styles.container}>
<Image
source={{uri: movie.posters.thumbnail}}
style={styles.thumbnail}/>
<View style={styles.rightContainer}>
<Text style={styles.title}>{movie.title}</Text>
<Text style={styles.year}>{movie.year}</Text>
</View>
</View>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
rightContainer: {
flex: 1,
},
title: {
fontSize: 20,
marginBottom: 8,
textAlign: 'center',
},
year: {
textAlign: 'center',
},
thumbnail: {
width: 53,
height: 81,
},
listView: {
paddingTop: 20,
backgroundColor: '#F5FCFF',
},
});
AppRegistry.registerComponent('ReactNativeCouchbaseLiteExample', () => ReactNativeCouchbaseLiteExample);