-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.android.js
More file actions
148 lines (134 loc) · 3.23 KB
/
index.android.js
File metadata and controls
148 lines (134 loc) · 3.23 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
'use strict'
let React = require('react-native')
let {
AppRegistry,
ScrollView,
StyleSheet,
View,
Image,
ListView,
TouchableHighlight,
Text,
Alert
} = React
let RCTUIManager = require('NativeModules').UIManager
let styles = StyleSheet.create({
scrollView: {
backgroundColor: '#6A85B1',
height: 300
},
text: {
fontSize: 20,
color: '#888888',
left: 80,
top: 20,
height: 40,
},
button: {
margin: 7,
padding: 5,
alignItems: 'center',
backgroundColor: '#eaeaea',
borderRadius: 3,
height: 100
},
icon: {
alignItems: 'center',
marginBottom: 10
}
})
let LoadingImg = React.createClass({
getInitialState: function() {
return {
show: true
}
},
render: function() {
let loadingStyle
if(this.state.show == true){
loadingStyle = {
opacity: 1
}
}
else {
loadingStyle = {
opacity: 0
}
}
return (
<View style={[loadingStyle, styles.icon]}>
<Image source={require('./images/loading.gif')}>
</Image>
</View>
)
}
})
let Item = React.createClass({
shouldComponentUpdate: function(nextProps, nextState) {
return false
},
render: function() {
return (
<View style={styles.button}>
<Text style={styles.text}>
{this.props.text}
</Text>
</View>
)
}
})
let createItemRow = (item, i) => <Item key={i} text={item.name} />
let requestLocked = false
let index = React.createClass({
title: '<ScrollView>',
description: 'To make content scrollable, wrap it within a <ScrollView> component',
getInitialState: function() {console.log('begin')
return {
Items: [],
viewHeight: 0,
scrollViewHeight: 0
}
},
componentWillMount: function() {
this.getData('', (data) => {
this.setState({Items: data.Items})
this.refs.loadingImg.setState({show: false})
})
},
getData: function(url, callback) {
setTimeout(() => {callback(require('./mockdata/index.json'))}, 2000)
},
isReachedBottom: function(scrollOffset) {
if(!requestLocked) {
if(this.state.scrollViewHeight <= this.state.viewHeight + scrollOffset.y) {
this.refs.loadingImg.setState({show: true})
requestLocked = true
this.getData('', (data) => {
let Items = this.state.Items.concat(data.Items)
this.setState({Items:Items})
requestLocked = false
this.refs.loadingImg.setState({show: false})
})
}
}
},
render: function() {
return (
<ScrollView
ref = {component=>{this._scrollView=component}}
automaticallyAdjustContentInsets={false}
onScroll={(event:Object) => {this.isReachedBottom(event.nativeEvent.contentOffset)}}
scrollEventThrottle={1000}
style={styles.scrollView}
onLayout={(evt) => {
this.setState({viewHeight: evt.nativeEvent.layout.height})
RCTUIManager.measure(this._scrollView.getInnerViewNode(), (...data) => { this.setState({scrollViewHeight: data[3]})})
}}
>
{this.state.Items.map(createItemRow)}
<LoadingImg ref="loadingImg"></LoadingImg>
</ScrollView>
)
}
})
AppRegistry.registerComponent('weekly', () => index)