Skip to content

Commit 3e641c8

Browse files
probertsproberts
authored andcommitted
Added changes from d-a-n#29
Added changes from d-a-n#32 Added changes from d-a-n#37 Added changes from d-a-n#40 Added Properties (default): optionContainerStyle: ({}) optionNumberOfLines (undefined) optionEllipsizeMode (tail)
1 parent a2d0b9b commit 3e641c8

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

index.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ let componentIndex = 0;
2323
const propTypes = {
2424
data: PropTypes.array,
2525
onChange: PropTypes.func,
26+
onClose: PropTypes.func,
2627
initValue: PropTypes.string,
2728
style: View.propTypes.style,
2829
selectStyle: View.propTypes.style,
30+
optionContainer: View.propTypes.style,
2931
optionStyle: View.propTypes.style,
3032
optionTextStyle: Text.propTypes.style,
33+
optionNumberOfLines: PropTypes.number,
34+
optionEllipsizeMode: PropTypes.oneOf(['head', 'middle', 'tail', 'clip']),
3135
sectionStyle: View.propTypes.style,
3236
sectionTextStyle: Text.propTypes.style,
3337
cancelStyle: View.propTypes.style,
@@ -39,11 +43,15 @@ const propTypes = {
3943
const defaultProps = {
4044
data: [],
4145
onChange: ()=> {},
46+
onClose: ()=> {},
4247
initValue: 'Select me!',
4348
style: {},
4449
selectStyle: {},
50+
optionContainer: {},
4551
optionStyle: {},
4652
optionTextStyle: {},
53+
optionNumberOfLines: undefined,
54+
optionEllipsizeMode: 'tail',
4755
sectionStyle: {},
4856
sectionTextStyle: {},
4957
cancelStyle: {},
@@ -60,16 +68,18 @@ export default class ModalPicker extends BaseComponent {
6068

6169
this._bind(
6270
'onChange',
71+
'onClose',
6372
'open',
6473
'close',
6574
'renderChildren'
6675
);
6776

6877
this.state = {
69-
animationType: 'slide',
78+
animationType: 'none',
7079
modalVisible: false,
7180
transparent: false,
7281
selected: 'please select'
82+
selectedObject: {},
7383
};
7484
}
7585

@@ -84,12 +94,23 @@ export default class ModalPicker extends BaseComponent {
8494
}
8595
}
8696

97+
componentWillUpdate(nextProps, nextState){
98+
if (nextState.modalVisible != this.state.modalVisible && nextState.modalVisible === false) {
99+
this.onClose(nextState.selectedObject);
100+
}
101+
}
102+
103+
87104
onChange(item) {
88105
this.props.onChange(item);
89-
this.setState({selected: item.label});
106+
this.setState({selected: item.label, selectedObject: item});
90107
this.close();
91108
}
92109

110+
onClose(item) {
111+
this.props.onClose(item);
112+
}
113+
93114
close() {
94115
this.setState({
95116
modalVisible: false
@@ -114,7 +135,9 @@ export default class ModalPicker extends BaseComponent {
114135
return (
115136
<TouchableOpacity key={option.key} onPress={()=>this.onChange(option)}>
116137
<View style={[styles.optionStyle, this.props.optionStyle]}>
117-
<Text style={[styles.optionTextStyle,this.props.optionTextStyle]}>{option.label}</Text>
138+
<Text numberOfLines={this.props.optionNumberOfLines}
139+
ellipsizeMode={this.props.optionEllipsizeMode}
140+
style={[styles.optionTextStyle,this.props.optionTextStyle]}>{option.label}</Text>
118141
</View>
119142
</TouchableOpacity>)
120143
}
@@ -129,9 +152,10 @@ export default class ModalPicker extends BaseComponent {
129152
});
130153

131154
return (
155+
132156
<View style={[styles.overlayStyle, this.props.overlayStyle]} key={'modalPicker'+(componentIndex++)}>
133-
<View style={styles.optionContainer}>
134-
<ScrollView keyboardShouldPersistTaps>
157+
<View style={[styles.optionContainer, this.props.optionContainer]}>
158+
<ScrollView keyboardShouldPersistTaps='always'>
135159
<View style={{paddingHorizontal:10}}>
136160
{options}
137161
</View>

style.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,33 @@ const PADDING = 8;
88
const BORDER_RADIUS = 5;
99
const FONT_SIZE = 16;
1010
const HIGHLIGHT_COLOR = 'rgba(0,118,255,0.9)';
11-
const OPTION_CONTAINER_HEIGHT = 400;
1211

1312
export default StyleSheet.create({
1413

1514
overlayStyle: {
1615
width: width,
1716
height: height,
17+
padding: width*0.1,
18+
justifyContent: 'center',
1819
backgroundColor: 'rgba(0,0,0,0.7)'
1920
},
2021

2122
optionContainer: {
2223
borderRadius:BORDER_RADIUS,
23-
width:width*0.8,
24-
height:OPTION_CONTAINER_HEIGHT,
24+
flexShrink: 1,
25+
marginBottom: 8,
26+
padding: PADDING,
2527
backgroundColor:'rgba(255,255,255,0.8)',
26-
left:width*0.1,
27-
top:(height-OPTION_CONTAINER_HEIGHT)/2
2828
},
2929

3030
cancelContainer: {
31-
left:width*0.1,
32-
top:(height-OPTION_CONTAINER_HEIGHT)/2 + 10
31+
alignSelf: 'center'
3332
},
3433

3534
selectStyle: {
36-
flex: 1,
3735
borderColor: '#ccc',
3836
borderWidth: 1,
39-
padding: 8,
37+
padding: PADDING,
4038
borderRadius: BORDER_RADIUS
4139
},
4240

@@ -81,4 +79,4 @@ export default StyleSheet.create({
8179
textAlign: 'center',
8280
fontSize: FONT_SIZE
8381
}
84-
});
82+
});

0 commit comments

Comments
 (0)