/
listViewComponent2.js
155 lines (146 loc) · 3.87 KB
/
listViewComponent2.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
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
149
150
151
152
153
154
import React, {Component} from 'react';
import {
AppRegistry,
StyleSheet,
TextInput,
ListView,
TouchableOpacity,
TouchableHighlight,
Image,
Text,
Alert,
View
} from 'react-native';
//导入数据
import RadiusButton from "./RadiusButton";
//获取屏幕宽度
let Dimensions = require("Dimensions");
let {width} = Dimensions.get('window');
//常量设置
let cols = 3;
let cellWH = 100;
let vMargin = (width - cellWH * cols) / (cols + 1);
let hMargin = 20;
export const data = [
{
icon: require('../img/icon3.png'),
title: '播放视频',
"btn": "+10算力"
},
{
icon: require('../img/icon4.png'),
title: '阅读新闻',
"btn": "+10算力"
},
{
icon: require('../img/icon5.png'),
title: '通讯录',
"btn": "+10算力"
},
{
icon: require('../img/icon56.png'),
title: '支付',
"btn": "+10算力"
},
// {
// icon: require('../img/icon6.png'),
// title: '转入',
// "btn": "+10算力"
// },
// {
// icon: require('../img/icon7.png'),
// title: '转出',
// "btn": "+10算力"
// },
// {
// icon: require('../img/icon8.png'),
// title: '买入',
// "btn": "+10算力"
// },
// {
// icon: require('../img/icon9.png'),
// title: '卖出',
// "btn": "+10算力"
// },
];
export default class listViewComponent2 extends Component {
constructor(props) {
super(props);
//1.设置数据源
let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
//2.设置返回数据
this.state = {dataSource: ds.cloneWithRows(data)};
}
render() {
return (
<ListView
dataSource={this.state.dataSource}
renderRow={this._renderRow.bind(this)}
contentContainerStyle={styles.listViewStyle}
/>
);
}
_renderRow(rowData, sectionID, rowID, highlightRow) {
return (
<TouchableOpacity activeOpacity={0.5} onPress={() => {
this._onPress(rowData.title)
}}>
<View style={styles.innerViewStyle}>
<Image source={rowData.icon} style={styles.iconStyle}/>
<Text style={styles.textStyle}>{rowData.title}</Text>
<RadiusButton
btnName={rowData.btn}
textStyle={{
fontSize: 10,
color: '#ffffff',
}}
btnStyle={{
marginTop: 5,
width: 70,
height: 18,
borderRadius: 25,
}}
underlayColor='#4169e1'>
</RadiusButton>
</View>
</TouchableOpacity>
);
}
_onPress(e) {
if (e === '播放视频') {
this.props.navigate('Video');
} else if (e === '阅读新闻') {
// this.props.navigate('Movie');
this.props.navigate('News');
} else if (e === '通讯录') {
this.props.navigate('Contact');
} else if (e === '支付') {
this.props.navigate('Pay');
}
else {
alert(">>>点击 " + e);
}
}
}
const styles = StyleSheet.create({
listViewStyle: {
flexDirection: 'row',
flexWrap: 'wrap',
},
iconStyle: {
margin: 6,
width: 32,
height: 32,
},
innerViewStyle: {
width: cellWH,
height: cellWH,
marginLeft: vMargin,
marginTop: hMargin,
alignItems: 'center',
},
textStyle: {
fontSize: 8,
color: 'gray'
}
});