Skip to content

Commit 645d6f6

Browse files
committed
add pickerWidth prop
1 parent 9784b21 commit 645d6f6

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default class PickerAny extends React.Component {
2828
pickerTitleStyle: PropTypes.any,
2929
pickerToolBarStyle: PropTypes.any,
3030
pickerItemStyle: PropTypes.any,
31+
pickerWidth: PropTypes.number,
3132
pickerHeight: PropTypes.number,
3233
showDuration: PropTypes.number,
3334
pickerData: PropTypes.any.isRequired,
@@ -44,7 +45,8 @@ export default class PickerAny extends React.Component {
4445
showDuration: 300,
4546
onPickerDone: ()=>{},
4647
onPickerCancel: ()=>{},
47-
onValueChange: ()=>{}
48+
onValueChange: ()=>{},
49+
pickerWidth: width > height ? height:width
4850
};
4951

5052
constructor(props, context){
@@ -61,6 +63,9 @@ export default class PickerAny extends React.Component {
6163
}
6264

6365
shouldComponentUpdate(nextProps, nextState, context){
66+
if(nextState.pickerWidth !== this.state.pickerWidth) {
67+
return true;
68+
}
6469
if(JSON.stringify(nextState.selectedValue) === JSON.stringify(this.state.selectedValue)){
6570
return false;
6671
}
@@ -78,6 +83,7 @@ export default class PickerAny extends React.Component {
7883
let pickerTitleStyle = props.pickerTitleStyle;
7984
let pickerToolBarStyle = props.pickerToolBarStyle;
8085
let pickerItemStyle = props.pickerItemStyle;
86+
let pickerWidth = props.pickerWidth;
8187
let pickerHeight = props.pickerHeight;
8288
let showDuration = props.showDuration;
8389
let pickerData = props.pickerData;
@@ -125,6 +131,7 @@ export default class PickerAny extends React.Component {
125131
pickerTitleStyle,
126132
pickerToolBarStyle,
127133
pickerItemStyle,
134+
pickerWidth,
128135
pickerHeight,
129136
showDuration,
130137
pickerData,
@@ -341,7 +348,7 @@ export default class PickerAny extends React.Component {
341348
);
342349

343350
return (
344-
<View style={styles.pickerWrap}>
351+
<View style={[styles.pickerWrap, { width: this.state.pickerWidth }]}>
345352
<View style={styles.pickerWheel}>
346353
<Picker
347354
ref={'firstWheel'}
@@ -461,10 +468,11 @@ export default class PickerAny extends React.Component {
461468
render(){
462469
return (
463470
<Animated.View style={[styles.picker, {
471+
width: this.state.pickerWidth,
464472
height: this.state.pickerHeight,
465473
bottom: this.state.slideAnim
466474
}, this.state.style]}>
467-
<View style={[styles.pickerToolbar, this.state.pickerToolBarStyle]}>
475+
<View style={[styles.pickerToolbar, this.state.pickerToolBarStyle, { width: this.state.pickerWidth }]}>
468476
<View style={styles.pickerCancelBtn}>
469477
<Text style={[styles.pickerFinishBtnText, this.state.pickerBtnStyle]}
470478
onPress={this._pickerCancel.bind(this)}>{this.state.pickerCancelBtnText}</Text>
@@ -487,23 +495,20 @@ export default class PickerAny extends React.Component {
487495

488496
let styles = StyleSheet.create({
489497
picker: {
490-
width: width,
491498
position: 'absolute',
492499
bottom: 0,
493500
left: 0,
494501
backgroundColor: '#bdc0c7',
495502
overflow: 'hidden'
496503
},
497504
pickerWrap: {
498-
width: width,
499505
flexDirection: 'row'
500506
},
501507
pickerWheel: {
502508
flex: 1
503509
},
504510
pickerToolbar: {
505511
height: 30,
506-
width: width,
507512
backgroundColor: '#e6e6e6',
508513
flexDirection: 'row',
509514
borderTopWidth: 1,

0 commit comments

Comments
 (0)