@@ -27,19 +27,15 @@ import {
2727const TOUCHABLE_ELEMENTS = [ 'TouchableHighlight' , 'TouchableOpacity' , 'TouchableWithoutFeedback' , 'TouchableWithNativeFeedback' ] ;
2828
2929export default class ModalDropdown extends Component {
30- static defaultProps = {
31- disabled : false ,
32- defaultIndex : - 1 ,
33- defaultValue : 'Please select...' ,
34- options : null ,
35- } ;
36-
3730 static propTypes = {
3831 disabled : PropTypes . bool ,
3932 defaultIndex : PropTypes . number ,
4033 defaultValue : PropTypes . string ,
4134 options : PropTypes . array ,
4235
36+ animated : PropTypes . bool ,
37+ showsVerticalScrollIndicator : PropTypes . bool ,
38+
4339 style : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . object , PropTypes . array ] ) ,
4440 textStyle : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . object , PropTypes . array ] ) ,
4541 dropdownStyle : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . object , PropTypes . array ] ) ,
@@ -50,7 +46,16 @@ export default class ModalDropdown extends Component {
5046
5147 onDropdownWillShow : PropTypes . func ,
5248 onDropdownWillHide : PropTypes . func ,
53- onSelect : PropTypes . func ,
49+ onSelect : PropTypes . func
50+ } ;
51+
52+ static defaultProps = {
53+ disabled : false ,
54+ defaultIndex : - 1 ,
55+ defaultValue : 'Please select...' ,
56+ options : null ,
57+ animated : true ,
58+ showsVerticalScrollIndicator : true
5459 } ;
5560
5661 constructor ( props ) {
@@ -66,7 +71,7 @@ export default class ModalDropdown extends Component {
6671 loading : props . options == null ,
6772 showDropdown : false ,
6873 buttonText : props . defaultValue ,
69- selectedIndex : props . defaultIndex ,
74+ selectedIndex : props . defaultIndex
7075 } ;
7176 }
7277
@@ -86,7 +91,7 @@ export default class ModalDropdown extends Component {
8691 disabled : nextProps . disabled ,
8792 loading : nextProps . options == null ,
8893 buttonText : buttonText ,
89- selectedIndex : selectedIndex ,
94+ selectedIndex : selectedIndex
9095 } ) ;
9196 }
9297
@@ -111,14 +116,14 @@ export default class ModalDropdown extends Component {
111116 show ( ) {
112117 this . _updatePosition ( ( ) => {
113118 this . setState ( {
114- showDropdown : true ,
119+ showDropdown : true
115120 } ) ;
116121 } ) ;
117122 }
118123
119124 hide ( ) {
120125 this . setState ( {
121- showDropdown : false ,
126+ showDropdown : false
122127 } ) ;
123128 }
124129
@@ -137,7 +142,7 @@ export default class ModalDropdown extends Component {
137142
138143 this . setState ( {
139144 buttonText : value ,
140- selectedIndex : idx ,
145+ selectedIndex : idx
141146 } ) ;
142147 }
143148
@@ -171,10 +176,12 @@ export default class ModalDropdown extends Component {
171176 _renderModal ( ) {
172177 if ( this . state . showDropdown && this . _buttonFrame ) {
173178 let frameStyle = this . _calcPosition ( ) ;
179+ let animationType = this . props . animated ? 'fade' : 'none' ;
174180 return (
175- < Modal animationType = 'fade'
181+ < Modal animationType = { animationType }
176182 transparent = { true }
177- onRequestClose = { this . _onRequestClose . bind ( this ) } >
183+ onRequestClose = { this . _onRequestClose . bind ( this ) }
184+ supportedOrientations = { [ 'portrait' , 'portrait-upside-down' , 'landscape' , 'landscape-left' , 'landscape-right' ] } >
178185 < TouchableWithoutFeedback onPress = { this . _onModalPress . bind ( this ) } >
179186 < View style = { styles . modal } >
180187 < View style = { [ styles . dropdown , this . props . dropdownStyle , frameStyle ] } >
@@ -203,7 +210,7 @@ export default class ModalDropdown extends Component {
203210 var style = {
204211 height : dropdownHeight ,
205212 top : showInBottom ? this . _buttonFrame . y + this . _buttonFrame . h : Math . max ( 0 , this . _buttonFrame . y - dropdownHeight ) ,
206- }
213+ } ;
207214
208215 if ( showInLeft ) {
209216 style . left = this . _buttonFrame . x ;
@@ -250,28 +257,29 @@ export default class ModalDropdown extends Component {
250257 renderRow = { this . _renderRow . bind ( this ) }
251258 renderSeparator = { this . props . renderSeparator || this . _renderSeparator . bind ( this ) }
252259 automaticallyAdjustContentInsets = { false }
260+ showsVerticalScrollIndicator = { this . props . showsVerticalScrollIndicator }
253261 />
254262 ) ;
255263 }
256264
257265 get _dataSource ( ) {
258266 let ds = new ListView . DataSource ( {
259- rowHasChanged : ( r1 , r2 ) => r1 !== r2 ,
267+ rowHasChanged : ( r1 , r2 ) => r1 !== r2
260268 } ) ;
261269 return ds . cloneWithRows ( this . props . options ) ;
262270 }
263271
264272 _renderRow ( rowData , sectionID , rowID , highlightRow ) {
265273 let key = `row_${ rowID } ` ;
266- let highlighted = rowID == this . state . selectedIndex
274+ let highlighted = rowID == this . state . selectedIndex ;
267275 let row = ! this . props . renderRow ?
268276 ( < Text style = { [ styles . rowText , highlighted && styles . highlightedRowText ] } >
269277 { rowData }
270278 </ Text > ) :
271279 this . props . renderRow ( rowData , rowID , highlighted ) ;
272280 let preservedProps = {
273281 key : key ,
274- onPress : ( ) => this . _onRowPress ( rowData , sectionID , rowID , highlightRow ) ,
282+ onPress : ( ) => this . _onRowPress ( rowData , sectionID , rowID , highlightRow )
275283 } ;
276284 if ( TOUCHABLE_ELEMENTS . find ( name => name == row . type . displayName ) ) {
277285 var props = { ...row . props } ;
@@ -333,13 +341,13 @@ export default class ModalDropdown extends Component {
333341 this . _nextIndex = rowID ;
334342 this . setState ( {
335343 buttonText : rowData . toString ( ) ,
336- selectedIndex : rowID ,
344+ selectedIndex : rowID
337345 } ) ;
338346 }
339347 if ( ! this . props . onDropdownWillHide ||
340348 this . props . onDropdownWillHide ( ) !== false ) {
341349 this . setState ( {
342- showDropdown : false ,
350+ showDropdown : false
343351 } ) ;
344352 }
345353 }
@@ -354,13 +362,13 @@ export default class ModalDropdown extends Component {
354362
355363const styles = StyleSheet . create ( {
356364 button : {
357- justifyContent : 'center' ,
365+ justifyContent : 'center'
358366 } ,
359367 buttonText : {
360- fontSize : 12 ,
368+ fontSize : 12
361369 } ,
362370 modal : {
363- flexGrow : 1 ,
371+ flexGrow : 1
364372 } ,
365373 dropdown : {
366374 position : 'absolute' ,
@@ -369,10 +377,10 @@ const styles = StyleSheet.create({
369377 borderColor : 'lightgray' ,
370378 borderRadius : 2 ,
371379 backgroundColor : 'white' ,
372- justifyContent : 'center' ,
380+ justifyContent : 'center'
373381 } ,
374382 loading : {
375- alignSelf : 'center' ,
383+ alignSelf : 'center'
376384 } ,
377385 list : {
378386 //flexGrow: 1,
@@ -383,13 +391,13 @@ const styles = StyleSheet.create({
383391 fontSize : 11 ,
384392 color : 'gray' ,
385393 backgroundColor : 'white' ,
386- textAlignVertical : 'center' ,
394+ textAlignVertical : 'center'
387395 } ,
388396 highlightedRowText : {
389- color : 'black' ,
397+ color : 'black'
390398 } ,
391399 separator : {
392400 height : StyleSheet . hairlineWidth ,
393- backgroundColor : 'lightgray' ,
401+ backgroundColor : 'lightgray'
394402 }
395403} ) ;
0 commit comments