Skip to content

Commit

Permalink
优化部分代码
Browse files Browse the repository at this point in the history
  • Loading branch information
ruoru committed Mar 31, 2017
1 parent b58a43d commit 1148af5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
2 changes: 0 additions & 2 deletions src/components/picker/city_picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ class CityPicker extends React.Component {
text = this.state.text;
}


//console.log(groups)
this.setState({
groups,
text,
Expand Down
17 changes: 9 additions & 8 deletions src/components/picker/picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,27 @@ class Picker extends Component {

constructor(props){
super(props);
const { defaultSelect, groups, actions, lang, onCancel } = props;

this.state = {
selected: this.props.defaultSelect ? this.props.defaultSelect : Array(this.props.groups.length).fill(-1),
actions: this.props.actions.length > 0 ? this.props.actions : [{
label: this.props.lang.leftBtn,
onClick: e=>this.handleClose( ()=> {if (this.props.onCancel) this.props.onCancel(e);} )
selected: defaultSelect ? defaultSelect : Array(groups.length).fill(-1),
actions: actions.length > 0 ? actions : [{
label: lang.leftBtn,
onClick: e=>this.handleClose( () => {if (onCancel) onCancel(e);} )
},
{
label: this.props.lang.rightBtn,
onClick: e=>this.handleChanges()
label: lang.rightBtn,
onClick: e=>this.handleConfirm()
}],
closing: false
};

this.handleChanges = this.handleChanges.bind(this);
this.handleConfirm = this.handleConfirm.bind(this);
this.handleChange = this.handleChange.bind(this);
this.handleClose = this.handleClose.bind(this);
}

handleChanges(){
handleConfirm(){
this.handleClose( ()=> { if (this.props.onChange) this.props.onChange(this.state.selected, this); } );
}

Expand Down
27 changes: 13 additions & 14 deletions src/components/picker/picker_group.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ class PickerGroup extends Component {
super(props);

this.state = {
touching: false,
ogY: 0,
ogTranslate: 0,
touchId: undefined,
translate: 0,
totalHeight: 0,
selectedIndex: 0,
animating: this.props.animation
translate : 0,
selectedIndex : 0,
animating : props.animation,
touching : false,
ogY : 0,
ogTranslate : 0,
touchId : undefined,
totalHeight : 0,
};

this.handleTouchStart = this.handleTouchStart.bind(this);
Expand Down Expand Up @@ -97,13 +97,12 @@ class PickerGroup extends Component {

handleTouchStart(e){
if (this.state.touching || this.props.items.length <= 1) return;

this.setState({
touching: true,
ogTranslate: this.state.translate,
touchId: e.targetTouches[0].identifier,
ogY: this.state.translate === 0 ? e.targetTouches[0].pageY : e.targetTouches[0].pageY - this.state.translate,
animating: false
touching : true,
ogTranslate : this.state.translate,
touchId : e.targetTouches[0].identifier,
ogY : e.targetTouches[0].pageY - this.state.translate,
animating : false
});
}

Expand Down

0 comments on commit 1148af5

Please sign in to comment.