-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
45 lines (38 loc) · 1.25 KB
/
index.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
var React = require('react-native')
var {Text, TouchableHighlight, View} = React
var styles = require('./styles.js')
var Listitem = React.createClass({
getDefaultProps: function() {
return {
onPress: null,
text: null,
underlayColor: "rgba(0,0,0,.015)",
}
}
, _handlePress: function() {
var onPress = this.props.onPress
if (onPress) onPress()
}
, render: function() {
var self = this
var p = self.props
// style container (for backgroundColor and indent)
var styleLiContainer = [styles.liContainer]
if (p.backgroundColor) styleLiContainer.push([{ backgroundColor: p.backgroundColor }])
if (p.indent > -1) styleLiContainer.push([{ paddingLeft: p.indent }])
var listitemChild = <Text style={[styles.liText, p.styleText]}>{p.text}</Text>
if (p.children) var listitemChild = <View>{p.children}</View>
var listitem = <View style={[styles.li, p.style]}>{listitemChild}</View>
return (
p.onPress ?
<TouchableHighlight
style={styleLiContainer}
underlayColor={p.underlayColor}
onPress={self._handlePress}>
{listitem}
</TouchableHighlight>
: <View style={styleLiContainer}>{listitem}</View>
)
}
})
module.exports = Listitem