-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.android.js
100 lines (99 loc) · 2.44 KB
/
index.android.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
'use strict';
/* Android base. */
var React = require('react');
var ReactNative = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
ViewPagerAndroid,
ToolbarAndroid,
} = ReactNative;
var ShareTab = require('./App/Views/ShareTab');
var ListTab = require('./App/Views/ListTab');
var api = require('./App/Network/api');
var ConnectLoveDemo = React.createClass({
getInitialState: function() {
return {
page: 0,
commentCount: 0,
data: [
{
"id": 0,
"author": "Loading",
"text": "Data",
"ds": "......"
},
],
};
},
// Reuse componentDidMount and handleCommentSubmit.
componentDidMount: function() {
api.getCommentUpdateStates.bind(this)();
},
handleCommentSubmit: function(comment){
api.postCommentUpdateStates.bind(this)(comment);
},
onPageSelected: function(e) {
this.setState({
page: e.nativeEvent.position,
commentCount: 0,
});
},
goPage: function(page) {
this.viewPager.setPage(page);
this.setState({
page: page,
commentCount: 0,
});
},
goNextPage: function(page) {
var nextPage = (this.state.page == 0) ? 1: 0;
this.goPage(nextPage);
},
render: function() {
var badgeCount = (this.state.commentCount > 0) ?
(' (' + this.state.commentCount + ')') : '';
// Toolbar text is dependent on what current page is.
var titleText = (this.state.page == 0) ?
('Comments' + badgeCount) : 'Share'
return (
<View style={styles.container}>
<ToolbarAndroid
actions={[{title: titleText, show: 'always'}]}
style={styles.toolBar}
title='Connecting-Love'
onActionSelected={this.goNextPage} />
<ViewPagerAndroid
style={styles.viewPager}
pageMargin={10}
onPageSelected={this.onPageSelected}
ref={viewPager => {this.viewPager = viewPager; }}
>
<View>
<ShareTab onCommentSubmit={this.handleCommentSubmit}/>
</View>
<View>
<ListTab data={this.state.data}/>
</View>
</ViewPagerAndroid>
</View>
);
}
})
;
var styles = StyleSheet.create({
viewPager: {
flex: 1,
},
container: {
flex: 1,
backgroundColor: 'white'
},
toolBar: {
backgroundColor: 'whitesmoke',
height: 50,
},
});
AppRegistry.registerComponent('ConnectLoveDemo', () => ConnectLoveDemo);