Skip to content

Commit

Permalink
feat(location): add the unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
lulutia committed Jun 5, 2016
1 parent e9315f2 commit ea6f368
Show file tree
Hide file tree
Showing 30 changed files with 6,424 additions and 1,176 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
.idea
android
ios
601 changes: 314 additions & 287 deletions .idea/workspace.xml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
android
ios
.*
app/setup.js
node_modules
.idea
show.gif
Binary file modified android/.gradle/2.4/taskArtifacts/cache.properties.lock
Binary file not shown.
Binary file modified android/.gradle/2.4/taskArtifacts/fileHashes.bin
Binary file not shown.
Binary file modified android/.gradle/2.4/taskArtifacts/fileSnapshots.bin
Binary file not shown.
Binary file modified android/.gradle/2.4/taskArtifacts/taskArtifacts.bin
Binary file not shown.
64 changes: 33 additions & 31 deletions app/csetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let saveIndex = [];
class CPickerroll extends Component {

static propTypes = {
data: PropTypes.object,
data: PropTypes.object
};


Expand All @@ -36,7 +36,8 @@ class CPickerroll extends Component {
this._setEventBegin = this._setEventBegin.bind(this);
this._changeLayout = this._changeLayout.bind(this);
this._cancelChose = this._cancelChose.bind(this);
this.state = this._stateFromProps(this.props);
this._changeAnimateStatus = this._changeAnimateStatus.bind(this);
this.state = this._stateFromProps(props);
this.state.animatedHeight = new Animated.Value(height);
}

Expand All @@ -45,7 +46,7 @@ class CPickerroll extends Component {
let selectedValue = [];
let passData = [];
if(typeof props.selectIndex==='undefined'){
for(let temp=0;temp<props.level;temp++){
for (let temp=0;temp<props.level;temp++){
selectIndex.push(0);
}
}else{
Expand All @@ -72,10 +73,10 @@ class CPickerroll extends Component {
let selfStyle = props.selfStyle;
let inputStyle = props.inputStyle;
let animationType = props.animationType||'none';
let transparent = typeof props.transparent==='undefined'?true:props.transparent;
let visible = typeof props.visible==='undefined'?false:props.visible;
let enable = typeof props.enable==='undefined'?true:props.enable;
let inputValue = props.inputValue||'please chose';
let transparent = typeof props.transparent === 'undefined' ? true:props.transparent;
let visible = typeof props.visible === 'undefined' ? false:props.visible;
let enable = typeof props.enable === 'undefined' ? true:props.enable;
let inputValue = props.inputValue || 'please chose';
return {
selfStyle,
visible,
Expand All @@ -90,11 +91,13 @@ class CPickerroll extends Component {
};
}
_confirmChose(){
str = '';
for(let item of this.state.selectedValue){
str = str + item + ' ';
}
this.state.inputValue = str;
this._setModalVisible(false,'confirm');
return str;
}
_cancelChose(){
this.state.selectIndex.length=0;
Expand All @@ -110,6 +113,8 @@ class CPickerroll extends Component {
this.state.selectIndex.push(item2);
}
this._setModalVisible(false,'cancel');
return {saveChoseValue:saveChoseValue,saveData:saveData,saveIndex:saveIndex};

}
_setEventBegin(){
if(this.state.enable){
Expand All @@ -126,9 +131,9 @@ class CPickerroll extends Component {
saveIndex.push(item2);
}
this.setState({passData:this.state.passData,selectIndex:this.state.selectIndex,selectedValue: this.state.selectedValue});
this._setModalVisible(true)
this._setModalVisible(true);
this.refs.test.blur()
str = '';
return {saveChoseValue:saveChoseValue,saveData:saveData,saveIndex:saveIndex};
}

}
Expand All @@ -143,25 +148,23 @@ class CPickerroll extends Component {
Animated.timing(
this.state.animatedHeight,
{toValue: height}
).start(() => {
if(type==='confirm'){
this.setState({visible:visible},()=>{
this.setState({inputValue: str});
if(this.props.onResult){
this.props.onResult(str);
}
})
}
else{
this.setState({visible:visible});
this.setState({passData: this.state.passData,selectIndex:this.state.selectIndex,selectedValue: this.state.selectedValue});
).start(() => this._changeAnimateStatus(type))
}
}
_changeAnimateStatus(type){
if (type==='confirm'){
this.setState({visible:false},()=>{
this.setState({inputValue: str});
if(this.props.onResult){
this.props.onResult(str);
}
})

}

else if(type=='cancel'){
this.setState({visible:false});
this.setState({passData: this.state.passData,selectIndex:this.state.selectIndex,selectedValue: this.state.selectedValue});
}
}

_changeLayout(value,index){
this.state.selectedValue.splice(index,1,value);
this.state.passData.length = index+1;
Expand Down Expand Up @@ -195,7 +198,7 @@ class CPickerroll extends Component {
let innerContainerTransparentStyle = this.state.transparent
? {backgroundColor: '#fff', padding: 20}
: null;
console.log(this.state.passData);

return (
<View style={styles.container}>
<Modal
Expand All @@ -208,12 +211,12 @@ class CPickerroll extends Component {
<Animated.View style={[styles.innerContainer, innerContainerTransparentStyle,{marginTop:this.state.animatedHeight}]}>
<View style={styles.nav}>
<TouchableOpacity style={styles.confirm}>
<Text onPress={() => {this. _confirmChose()
}}
<Text className={"confirm"} onPress={() => {this. _confirmChose()}}
style={{textAlign:'left',marginLeft:10}} >Confirm</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.cancel} >
<Text
className={"cancel"}
style={{textAlign:'right',marginRight:10}}
onPress={() => {this._cancelChose()
}}
Expand All @@ -225,14 +228,14 @@ class CPickerroll extends Component {
return(
<CPicker
key = {index}
className = {"test"+index}
style = {{flex:1}}
selectIndex = {this.state.selectIndex[index]}
selectedValue = {this.state.selectedValue[index]}
pickerStyle = {{flex:1}}
data = {this.state.passData[index]}
passData = {this.state.passData}
onValueChange={(newValue,newIndex) => {
this._changeLayout(newValue,index)}}
onValueChange={(newValue,newIndex) => {this._changeLayout(newValue,index)}}
>
{ Platform.OS === 'ios' &&((this.state.passData[index]).map((carMake) => (
<PickerItem
Expand All @@ -253,8 +256,7 @@ class CPickerroll extends Component {
style = {[styles.textInput,this.props.inputStyle]}
ref = 'test'
multiline={ true }
onFocus={() => { this._setEventBegin()
}}
onFocus={() => { this._setEventBegin()}}
placeholder={this.state.inputValue}
value={this.state.inputValue}
/>
Expand Down
Loading

0 comments on commit ea6f368

Please sign in to comment.