Skip to content

Commit ea6f368

Browse files
committed
feat(location): add the unit test
1 parent e9315f2 commit ea6f368

30 files changed

+6424
-1176
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
22
.idea
3+
android
4+
ios

.idea/workspace.xml

Lines changed: 314 additions & 287 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
android
22
ios
33
.*
4-
app/setup.js
54
node_modules
65
.idea
76
show.gif
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
382 Bytes
Binary file not shown.
764 Bytes
Binary file not shown.

app/csetup.js

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let saveIndex = [];
2727
class CPickerroll extends Component {
2828

2929
static propTypes = {
30-
data: PropTypes.object,
30+
data: PropTypes.object
3131
};
3232

3333

@@ -36,7 +36,8 @@ class CPickerroll extends Component {
3636
this._setEventBegin = this._setEventBegin.bind(this);
3737
this._changeLayout = this._changeLayout.bind(this);
3838
this._cancelChose = this._cancelChose.bind(this);
39-
this.state = this._stateFromProps(this.props);
39+
this._changeAnimateStatus = this._changeAnimateStatus.bind(this);
40+
this.state = this._stateFromProps(props);
4041
this.state.animatedHeight = new Animated.Value(height);
4142
}
4243

@@ -45,7 +46,7 @@ class CPickerroll extends Component {
4546
let selectedValue = [];
4647
let passData = [];
4748
if(typeof props.selectIndex==='undefined'){
48-
for(let temp=0;temp<props.level;temp++){
49+
for (let temp=0;temp<props.level;temp++){
4950
selectIndex.push(0);
5051
}
5152
}else{
@@ -72,10 +73,10 @@ class CPickerroll extends Component {
7273
let selfStyle = props.selfStyle;
7374
let inputStyle = props.inputStyle;
7475
let animationType = props.animationType||'none';
75-
let transparent = typeof props.transparent==='undefined'?true:props.transparent;
76-
let visible = typeof props.visible==='undefined'?false:props.visible;
77-
let enable = typeof props.enable==='undefined'?true:props.enable;
78-
let inputValue = props.inputValue||'please chose';
76+
let transparent = typeof props.transparent === 'undefined' ? true:props.transparent;
77+
let visible = typeof props.visible === 'undefined' ? false:props.visible;
78+
let enable = typeof props.enable === 'undefined' ? true:props.enable;
79+
let inputValue = props.inputValue || 'please chose';
7980
return {
8081
selfStyle,
8182
visible,
@@ -90,11 +91,13 @@ class CPickerroll extends Component {
9091
};
9192
}
9293
_confirmChose(){
94+
str = '';
9395
for(let item of this.state.selectedValue){
9496
str = str + item + ' ';
9597
}
9698
this.state.inputValue = str;
9799
this._setModalVisible(false,'confirm');
100+
return str;
98101
}
99102
_cancelChose(){
100103
this.state.selectIndex.length=0;
@@ -110,6 +113,8 @@ class CPickerroll extends Component {
110113
this.state.selectIndex.push(item2);
111114
}
112115
this._setModalVisible(false,'cancel');
116+
return {saveChoseValue:saveChoseValue,saveData:saveData,saveIndex:saveIndex};
117+
113118
}
114119
_setEventBegin(){
115120
if(this.state.enable){
@@ -126,9 +131,9 @@ class CPickerroll extends Component {
126131
saveIndex.push(item2);
127132
}
128133
this.setState({passData:this.state.passData,selectIndex:this.state.selectIndex,selectedValue: this.state.selectedValue});
129-
this._setModalVisible(true)
134+
this._setModalVisible(true);
130135
this.refs.test.blur()
131-
str = '';
136+
return {saveChoseValue:saveChoseValue,saveData:saveData,saveIndex:saveIndex};
132137
}
133138

134139
}
@@ -143,25 +148,23 @@ class CPickerroll extends Component {
143148
Animated.timing(
144149
this.state.animatedHeight,
145150
{toValue: height}
146-
).start(() => {
147-
if(type==='confirm'){
148-
this.setState({visible:visible},()=>{
149-
this.setState({inputValue: str});
150-
if(this.props.onResult){
151-
this.props.onResult(str);
152-
}
153-
})
154-
}
155-
else{
156-
this.setState({visible:visible});
157-
this.setState({passData: this.state.passData,selectIndex:this.state.selectIndex,selectedValue: this.state.selectedValue});
151+
).start(() => this._changeAnimateStatus(type))
152+
}
153+
}
154+
_changeAnimateStatus(type){
155+
if (type==='confirm'){
156+
this.setState({visible:false},()=>{
157+
this.setState({inputValue: str});
158+
if(this.props.onResult){
159+
this.props.onResult(str);
158160
}
159161
})
160-
161162
}
162-
163+
else if(type=='cancel'){
164+
this.setState({visible:false});
165+
this.setState({passData: this.state.passData,selectIndex:this.state.selectIndex,selectedValue: this.state.selectedValue});
166+
}
163167
}
164-
165168
_changeLayout(value,index){
166169
this.state.selectedValue.splice(index,1,value);
167170
this.state.passData.length = index+1;
@@ -195,7 +198,7 @@ class CPickerroll extends Component {
195198
let innerContainerTransparentStyle = this.state.transparent
196199
? {backgroundColor: '#fff', padding: 20}
197200
: null;
198-
console.log(this.state.passData);
201+
199202
return (
200203
<View style={styles.container}>
201204
<Modal
@@ -208,12 +211,12 @@ class CPickerroll extends Component {
208211
<Animated.View style={[styles.innerContainer, innerContainerTransparentStyle,{marginTop:this.state.animatedHeight}]}>
209212
<View style={styles.nav}>
210213
<TouchableOpacity style={styles.confirm}>
211-
<Text onPress={() => {this. _confirmChose()
212-
}}
214+
<Text className={"confirm"} onPress={() => {this. _confirmChose()}}
213215
style={{textAlign:'left',marginLeft:10}} >Confirm</Text>
214216
</TouchableOpacity>
215217
<TouchableOpacity style={styles.cancel} >
216218
<Text
219+
className={"cancel"}
217220
style={{textAlign:'right',marginRight:10}}
218221
onPress={() => {this._cancelChose()
219222
}}
@@ -225,14 +228,14 @@ class CPickerroll extends Component {
225228
return(
226229
<CPicker
227230
key = {index}
231+
className = {"test"+index}
228232
style = {{flex:1}}
229233
selectIndex = {this.state.selectIndex[index]}
230234
selectedValue = {this.state.selectedValue[index]}
231235
pickerStyle = {{flex:1}}
232236
data = {this.state.passData[index]}
233237
passData = {this.state.passData}
234-
onValueChange={(newValue,newIndex) => {
235-
this._changeLayout(newValue,index)}}
238+
onValueChange={(newValue,newIndex) => {this._changeLayout(newValue,index)}}
236239
>
237240
{ Platform.OS === 'ios' &&((this.state.passData[index]).map((carMake) => (
238241
<PickerItem
@@ -253,8 +256,7 @@ class CPickerroll extends Component {
253256
style = {[styles.textInput,this.props.inputStyle]}
254257
ref = 'test'
255258
multiline={ true }
256-
onFocus={() => { this._setEventBegin()
257-
}}
259+
onFocus={() => { this._setEventBegin()}}
258260
placeholder={this.state.inputValue}
259261
value={this.state.inputValue}
260262
/>

0 commit comments

Comments
 (0)