Repository navigation
Expand file tree
/
Copy pathMenuItem.js
More file actions
119 lines (113 loc) · 2.83 KB
/
Copy pathMenuItem.js
File metadata and controls
119 lines (113 loc) · 2.83 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
import React from 'react'
import { TouchableOpacity, Text, StyleSheet, Image, View } from 'react-native'
import { scaleSize } from '../../utils'
import { size, color } from '../../styles'
const ITEM_HEIGHT = scaleSize(80)
const VIEW_WIDTH = scaleSize(360)
export default class MenuItem extends React.PureComponent {
props: {
data: Object,
onPress?: () => {}, // 选中item的回调
index: number,
rowHeight: number,
highLight?: boolean,
style?: Object,
}
static defaultProps = {
highLight: false,
rowHeight: ITEM_HEIGHT,
}
itemAction = () => {
this.props.onPress &&
this.props.onPress({
data: this.props.data,
index: this.props.index,
})
}
render() {
return (
<TouchableOpacity
key={this.props.data.key}
activeOpacity={0.8}
underlayColor="#4680DF"
style={[
styles.item,
{ height: this.props.rowHeight, width: '100%' },
this.props.style,
]}
onPress={() => {
if (this.props.data && this.props.data.key) {
this.list &&
this.list.scrollToIndex({
index: this.props.index,
viewPosition: 0.5,
})
this.itemAction()
}
}}
>
{this.props.data.icon && (
<View style={styles.iconView}>
<Image
resizeMode={'contain'}
style={styles.icon}
source={
this.props.highLight && this.props.data.highLightIcon
? this.props.data.highLightIcon
: this.props.data.icon
}
/>
</View>
)}
<Text style={this.props.highLight ? styles.textHighLight : styles.text}>
{this.props.data.key}
</Text>
</TouchableOpacity>
)
}
}
const styles = StyleSheet.create({
menuContainer: {
flexDirection: 'column',
backgroundColor: color.bgW,
justifyContent: 'center',
alignItems: 'center',
},
selectedView: {
position: 'absolute',
height: ITEM_HEIGHT,
backgroundColor: '#4680DF',
width: VIEW_WIDTH,
},
item: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
height: ITEM_HEIGHT,
backgroundColor: 'transparent',
width: '100%',
},
text: {
color: color.font_color_white,
fontSize: size.fontSize.fontSizeLg,
backgroundColor: 'transparent',
textAlign: 'center',
},
textHighLight: {
color: color.content_white,
fontWeight: 'bold',
fontSize: size.fontSize.fontSizeXl,
backgroundColor: 'transparent',
textAlign: 'center',
},
iconView: {
height: scaleSize(60),
width: scaleSize(100),
justifyContent: 'center',
alignItems: 'center',
},
icon: {
height: scaleSize(60),
width: scaleSize(60),
},
})