@@ -23,11 +23,15 @@ let componentIndex = 0;
23
23
const propTypes = {
24
24
data : PropTypes . array ,
25
25
onChange : PropTypes . func ,
26
+ onClose : PropTypes . func ,
26
27
initValue : PropTypes . string ,
27
28
style : View . propTypes . style ,
28
29
selectStyle : View . propTypes . style ,
30
+ optionContainer : View . propTypes . style ,
29
31
optionStyle : View . propTypes . style ,
30
32
optionTextStyle : Text . propTypes . style ,
33
+ optionNumberOfLines : PropTypes . number ,
34
+ optionEllipsizeMode : PropTypes . oneOf ( [ 'head' , 'middle' , 'tail' , 'clip' ] ) ,
31
35
sectionStyle : View . propTypes . style ,
32
36
sectionTextStyle : Text . propTypes . style ,
33
37
cancelStyle : View . propTypes . style ,
@@ -39,11 +43,15 @@ const propTypes = {
39
43
const defaultProps = {
40
44
data : [ ] ,
41
45
onChange : ( ) => { } ,
46
+ onClose : ( ) => { } ,
42
47
initValue : 'Select me!' ,
43
48
style : { } ,
44
49
selectStyle : { } ,
50
+ optionContainer : { } ,
45
51
optionStyle : { } ,
46
52
optionTextStyle : { } ,
53
+ optionNumberOfLines : undefined ,
54
+ optionEllipsizeMode : 'tail' ,
47
55
sectionStyle : { } ,
48
56
sectionTextStyle : { } ,
49
57
cancelStyle : { } ,
@@ -60,16 +68,18 @@ export default class ModalPicker extends BaseComponent {
60
68
61
69
this . _bind (
62
70
'onChange' ,
71
+ 'onClose' ,
63
72
'open' ,
64
73
'close' ,
65
74
'renderChildren'
66
75
) ;
67
76
68
77
this . state = {
69
- animationType : 'slide ' ,
78
+ animationType : 'none ' ,
70
79
modalVisible : false ,
71
80
transparent : false ,
72
81
selected : 'please select'
82
+ selectedObject : { } ,
73
83
} ;
74
84
}
75
85
@@ -84,12 +94,23 @@ export default class ModalPicker extends BaseComponent {
84
94
}
85
95
}
86
96
97
+ componentWillUpdate ( nextProps , nextState ) {
98
+ if ( nextState . modalVisible != this . state . modalVisible && nextState . modalVisible === false ) {
99
+ this . onClose ( nextState . selectedObject ) ;
100
+ }
101
+ }
102
+
103
+
87
104
onChange ( item ) {
88
105
this . props . onChange ( item ) ;
89
- this . setState ( { selected : item . label } ) ;
106
+ this . setState ( { selected : item . label , selectedObject : item } ) ;
90
107
this . close ( ) ;
91
108
}
92
109
110
+ onClose ( item ) {
111
+ this . props . onClose ( item ) ;
112
+ }
113
+
93
114
close ( ) {
94
115
this . setState ( {
95
116
modalVisible : false
@@ -114,7 +135,9 @@ export default class ModalPicker extends BaseComponent {
114
135
return (
115
136
< TouchableOpacity key = { option . key } onPress = { ( ) => this . onChange ( option ) } >
116
137
< 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 >
118
141
</ View >
119
142
</ TouchableOpacity > )
120
143
}
@@ -129,9 +152,10 @@ export default class ModalPicker extends BaseComponent {
129
152
} ) ;
130
153
131
154
return (
155
+
132
156
< 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' >
135
159
< View style = { { paddingHorizontal :10 } } >
136
160
{ options }
137
161
</ View >
0 commit comments