Skip to content

Commit 1148af5

Browse files
author
ruoru
committed
优化部分代码
1 parent b58a43d commit 1148af5

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

src/components/picker/city_picker.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ class CityPicker extends React.Component {
9999
text = this.state.text;
100100
}
101101

102-
103-
//console.log(groups)
104102
this.setState({
105103
groups,
106104
text,

src/components/picker/picker.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,27 @@ class Picker extends Component {
5959

6060
constructor(props){
6161
super(props);
62+
const { defaultSelect, groups, actions, lang, onCancel } = props;
6263

6364
this.state = {
64-
selected: this.props.defaultSelect ? this.props.defaultSelect : Array(this.props.groups.length).fill(-1),
65-
actions: this.props.actions.length > 0 ? this.props.actions : [{
66-
label: this.props.lang.leftBtn,
67-
onClick: e=>this.handleClose( ()=> {if (this.props.onCancel) this.props.onCancel(e);} )
65+
selected: defaultSelect ? defaultSelect : Array(groups.length).fill(-1),
66+
actions: actions.length > 0 ? actions : [{
67+
label: lang.leftBtn,
68+
onClick: e=>this.handleClose( () => {if (onCancel) onCancel(e);} )
6869
},
6970
{
70-
label: this.props.lang.rightBtn,
71-
onClick: e=>this.handleChanges()
71+
label: lang.rightBtn,
72+
onClick: e=>this.handleConfirm()
7273
}],
7374
closing: false
7475
};
7576

76-
this.handleChanges = this.handleChanges.bind(this);
77+
this.handleConfirm = this.handleConfirm.bind(this);
7778
this.handleChange = this.handleChange.bind(this);
7879
this.handleClose = this.handleClose.bind(this);
7980
}
8081

81-
handleChanges(){
82+
handleConfirm(){
8283
this.handleClose( ()=> { if (this.props.onChange) this.props.onChange(this.state.selected, this); } );
8384
}
8485

src/components/picker/picker_group.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ class PickerGroup extends Component {
3030
super(props);
3131

3232
this.state = {
33-
touching: false,
34-
ogY: 0,
35-
ogTranslate: 0,
36-
touchId: undefined,
37-
translate: 0,
38-
totalHeight: 0,
39-
selectedIndex: 0,
40-
animating: this.props.animation
33+
translate : 0,
34+
selectedIndex : 0,
35+
animating : props.animation,
36+
touching : false,
37+
ogY : 0,
38+
ogTranslate : 0,
39+
touchId : undefined,
40+
totalHeight : 0,
4141
};
4242

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

9898
handleTouchStart(e){
9999
if (this.state.touching || this.props.items.length <= 1) return;
100-
101100
this.setState({
102-
touching: true,
103-
ogTranslate: this.state.translate,
104-
touchId: e.targetTouches[0].identifier,
105-
ogY: this.state.translate === 0 ? e.targetTouches[0].pageY : e.targetTouches[0].pageY - this.state.translate,
106-
animating: false
101+
touching : true,
102+
ogTranslate : this.state.translate,
103+
touchId : e.targetTouches[0].identifier,
104+
ogY : e.targetTouches[0].pageY - this.state.translate,
105+
animating : false
107106
});
108107
}
109108

0 commit comments

Comments
 (0)