@@ -23,11 +23,15 @@ let componentIndex = 0;
2323const 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 = {
3943const 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 >
0 commit comments