Commit 03b3b3c6 authored by zooble's avatar zooble

Merge pull request #24 from jimthedev/master

Add pickerWidth prop
parents 9784b210 a8b9faf4
...@@ -27,6 +27,7 @@ Needs react-native >= 0.14.2 ...@@ -27,6 +27,7 @@ Needs react-native >= 0.14.2
- <b>pickerCancelBtnText</b> string, tool bar's cancel ben text - <b>pickerCancelBtnText</b> string, tool bar's cancel ben text
- <b>pickerBtnStyle</b> textStylePropType, tool bar's btn style - <b>pickerBtnStyle</b> textStylePropType, tool bar's btn style
- <b>pickerToolBarStyle</b> viewStylePropType, tool bar's style - <b>pickerToolBarStyle</b> viewStylePropType, tool bar's style
- <b>pickerWidth</b> number, width of picker
- <b>pickerHeight</b> number, height of picker - <b>pickerHeight</b> number, height of picker
- <b>showDuration</b> number, animation of picker - <b>showDuration</b> number, animation of picker
- <b>pickerTitle</b> string, title of picker - <b>pickerTitle</b> string, title of picker
......
...@@ -28,6 +28,7 @@ export default class PickerAny extends React.Component { ...@@ -28,6 +28,7 @@ export default class PickerAny extends React.Component {
pickerTitleStyle: PropTypes.any, pickerTitleStyle: PropTypes.any,
pickerToolBarStyle: PropTypes.any, pickerToolBarStyle: PropTypes.any,
pickerItemStyle: PropTypes.any, pickerItemStyle: PropTypes.any,
pickerWidth: PropTypes.number,
pickerHeight: PropTypes.number, pickerHeight: PropTypes.number,
showDuration: PropTypes.number, showDuration: PropTypes.number,
pickerData: PropTypes.any.isRequired, pickerData: PropTypes.any.isRequired,
...@@ -44,7 +45,8 @@ export default class PickerAny extends React.Component { ...@@ -44,7 +45,8 @@ export default class PickerAny extends React.Component {
showDuration: 300, showDuration: 300,
onPickerDone: ()=>{}, onPickerDone: ()=>{},
onPickerCancel: ()=>{}, onPickerCancel: ()=>{},
onValueChange: ()=>{} onValueChange: ()=>{},
pickerWidth: width > height ? height:width
}; };
constructor(props, context){ constructor(props, context){
...@@ -61,6 +63,9 @@ export default class PickerAny extends React.Component { ...@@ -61,6 +63,9 @@ export default class PickerAny extends React.Component {
} }
shouldComponentUpdate(nextProps, nextState, context){ shouldComponentUpdate(nextProps, nextState, context){
if(nextState.pickerWidth !== this.state.pickerWidth) {
return true;
}
if(JSON.stringify(nextState.selectedValue) === JSON.stringify(this.state.selectedValue)){ if(JSON.stringify(nextState.selectedValue) === JSON.stringify(this.state.selectedValue)){
return false; return false;
} }
...@@ -78,6 +83,7 @@ export default class PickerAny extends React.Component { ...@@ -78,6 +83,7 @@ export default class PickerAny extends React.Component {
let pickerTitleStyle = props.pickerTitleStyle; let pickerTitleStyle = props.pickerTitleStyle;
let pickerToolBarStyle = props.pickerToolBarStyle; let pickerToolBarStyle = props.pickerToolBarStyle;
let pickerItemStyle = props.pickerItemStyle; let pickerItemStyle = props.pickerItemStyle;
let pickerWidth = props.pickerWidth;
let pickerHeight = props.pickerHeight; let pickerHeight = props.pickerHeight;
let showDuration = props.showDuration; let showDuration = props.showDuration;
let pickerData = props.pickerData; let pickerData = props.pickerData;
...@@ -125,6 +131,7 @@ export default class PickerAny extends React.Component { ...@@ -125,6 +131,7 @@ export default class PickerAny extends React.Component {
pickerTitleStyle, pickerTitleStyle,
pickerToolBarStyle, pickerToolBarStyle,
pickerItemStyle, pickerItemStyle,
pickerWidth,
pickerHeight, pickerHeight,
showDuration, showDuration,
pickerData, pickerData,
...@@ -341,7 +348,7 @@ export default class PickerAny extends React.Component { ...@@ -341,7 +348,7 @@ export default class PickerAny extends React.Component {
); );
return ( return (
<View style={styles.pickerWrap}> <View style={[styles.pickerWrap, { width: this.state.pickerWidth }]}>
<View style={styles.pickerWheel}> <View style={styles.pickerWheel}>
<Picker <Picker
ref={'firstWheel'} ref={'firstWheel'}
...@@ -461,10 +468,11 @@ export default class PickerAny extends React.Component { ...@@ -461,10 +468,11 @@ export default class PickerAny extends React.Component {
render(){ render(){
return ( return (
<Animated.View style={[styles.picker, { <Animated.View style={[styles.picker, {
width: this.state.pickerWidth,
height: this.state.pickerHeight, height: this.state.pickerHeight,
bottom: this.state.slideAnim bottom: this.state.slideAnim
}, this.state.style]}> }, this.state.style]}>
<View style={[styles.pickerToolbar, this.state.pickerToolBarStyle]}> <View style={[styles.pickerToolbar, this.state.pickerToolBarStyle, { width: this.state.pickerWidth }]}>
<View style={styles.pickerCancelBtn}> <View style={styles.pickerCancelBtn}>
<Text style={[styles.pickerFinishBtnText, this.state.pickerBtnStyle]} <Text style={[styles.pickerFinishBtnText, this.state.pickerBtnStyle]}
onPress={this._pickerCancel.bind(this)}>{this.state.pickerCancelBtnText}</Text> onPress={this._pickerCancel.bind(this)}>{this.state.pickerCancelBtnText}</Text>
...@@ -487,7 +495,6 @@ export default class PickerAny extends React.Component { ...@@ -487,7 +495,6 @@ export default class PickerAny extends React.Component {
let styles = StyleSheet.create({ let styles = StyleSheet.create({
picker: { picker: {
width: width,
position: 'absolute', position: 'absolute',
bottom: 0, bottom: 0,
left: 0, left: 0,
...@@ -495,7 +502,6 @@ let styles = StyleSheet.create({ ...@@ -495,7 +502,6 @@ let styles = StyleSheet.create({
overflow: 'hidden' overflow: 'hidden'
}, },
pickerWrap: { pickerWrap: {
width: width,
flexDirection: 'row' flexDirection: 'row'
}, },
pickerWheel: { pickerWheel: {
...@@ -503,7 +509,6 @@ let styles = StyleSheet.create({ ...@@ -503,7 +509,6 @@ let styles = StyleSheet.create({
}, },
pickerToolbar: { pickerToolbar: {
height: 30, height: 30,
width: width,
backgroundColor: '#e6e6e6', backgroundColor: '#e6e6e6',
flexDirection: 'row', flexDirection: 'row',
borderTopWidth: 1, borderTopWidth: 1,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment