Repository navigation
Expand file tree
/
Copy pathMultiPicker.js
More file actions
236 lines (225 loc) · 6.24 KB
/
Copy pathMultiPicker.js
File metadata and controls
236 lines (225 loc) · 6.24 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import * as React from 'react'
import { View, TouchableOpacity, Text, StyleSheet } from 'react-native'
import { FingerMenu } from '../../components'
import { scaleSize } from '../../utils'
import { size, color } from '../../styles'
import { getLanguage } from '../../language'
const styles = StyleSheet.create({
btnsView: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingHorizontal: scaleSize(50),
height: scaleSize(80),
},
btnView: {
flex: 1,
flexDirection: 'row',
height: scaleSize(80),
alignItems: 'center',
justifyContent: 'center',
},
linkView: {
flex: 1,
height: scaleSize(300),
flexDirection: 'row',
justifyContent: 'center',
},
btnText: {
fontSize: size.fontSize.fontSizeMd,
color: color.fontColorBlack,
textAlign: 'center',
backgroundColor: 'transparent',
},
list: {
maxHeight: (scaleSize(80) + 1) * 6, // 最多6条
// backgroundColor: 'transparent',
},
popView: {
flex: 1,
flexDirection: 'column',
backgroundColor: color.bgW,
},
})
export default class MultiPicker extends React.Component {
props: {
language: String,
confirm: () => {},
cancel: () => {},
popData: Array,
currentPopData: Object,
viewableItems?: number,
}
constructor(props) {
super(props)
this.currentFirstData =
this.props.popData &&
this.props.popData.length > 0 &&
this.props.popData[0]
this.state = {
secondData: this.currentFirstData.children,
}
this.update = false
}
shouldComponentUpdate(nextProps, nextState) {
return (
this.props.language !== nextProps.language ||
JSON.stringify(this.props.popData) !==
JSON.stringify(nextProps.popData) ||
JSON.stringify(this.props.currentPopData) !==
JSON.stringify(nextProps.currentPopData) ||
JSON.stringify(this.state) !== JSON.stringify(nextState)
)
}
setVisible = (visible, cb) => {
if (visible === undefined) {
visible = !this.state.visible
} else if (visible === this.state.visible) {
return
}
this.setState(
{
visible: visible,
},
() => {
if (cb && typeof cb === 'function') {
cb()
}
},
)
}
_getFirstDataIndex = () => {
for (let i = 0; i < this.props.popData.length; i++) {
if (
this.props.popData[i].key !== undefined &&
this.props.popData[i].key === this.currentFirstData.key
) {
return i
}
}
}
_getSecondDataIndex = () => {
let index = this._getFirstDataIndex()
let currentFirstData = this.props.popData[index]
for (let i = 0; i < currentFirstData.children.length; i++) {
if (
currentFirstData.children[i].key !== undefined &&
currentFirstData.children[i].key === currentFirstData.selectedItem.key
) {
return i
}
}
}
renderLinkList = () => {
return (
<View style={styles.linkView}>
<FingerMenu
style={{ flex: 1, width: '50%' }}
ref={ref => (this.firstMenu = ref)}
data={this.props.popData}
initialKey={
(this.props.currentPopData && this.props.currentPopData.key) ||
(this.props.popData.length > 0 && this.props.popData[0].key)
}
onScroll={item => {
this.currentFirstData = item
this.update = true
item &&
item.children &&
this.setState(
{
secondData: item.children,
},
() => {
this.update = false
this.secondMenu &&
this.secondMenu._scrollToIndex(this._getSecondDataIndex())
},
)
}}
onSelect={item => {
this.currentFirstData = item
this.update = true
item &&
item.children &&
this.setState(
{
secondData: item.children,
},
() => {
this.update = false
this.secondMenu &&
this.secondMenu._scrollToIndex(this._getSecondDataIndex())
},
)
}}
viewableItems={this.props.viewableItems}
/>
<FingerMenu
style={{ flex: 1, width: '50%' }}
ref={ref => (this.secondMenu = ref)}
data={this.state.secondData}
initialKey={this.currentFirstData.initItem.key}
onScroll={item => {
if (this.update) return
let index = this._getFirstDataIndex()
this.props.popData[index].selectedItem = item
}}
onSelect={item => {
if (this.update) return
let index = this._getFirstDataIndex()
this.props.popData[index].selectedItem = item
}}
viewableItems={this.props.viewableItems}
/>
</View>
)
}
renderBottom = () => {
return (
<View style={[styles.btnsView, { width: '100%' }]}>
<TouchableOpacity
style={[styles.btnView, { justifyContent: 'flex-start' }]}
onPress={() => {
if (this.props.cancel && typeof this.props.cancel === 'function') {
this.props.cancel()
}
}}
>
<Text style={styles.btnText}>
{
getLanguage(this.props.language || GLOBAL.language).Analyst_Labels
.CANCEL
}
</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.btnView, { justifyContent: 'flex-end' }]}
onPress={() => {
if (
this.props.confirm &&
typeof this.props.confirm === 'function'
) {
this.props.confirm(this.props.popData)
}
}}
>
<Text style={styles.btnText}>
{
getLanguage(this.props.language || GLOBAL.language).Analyst_Labels
.CONFIRM
}
</Text>
</TouchableOpacity>
</View>
)
}
render() {
return (
<View style={styles.popView}>
{this.renderBottom()}
{this.renderLinkList()}
</View>
)
}
}