@@ -48,6 +48,7 @@ export default class ModalDropdown extends Component {
48
48
adjustFrame : PropTypes . func ,
49
49
renderRow : PropTypes . func ,
50
50
renderSeparator : PropTypes . func ,
51
+ renderButtonText : PropTypes . func ,
51
52
52
53
onDropdownWillShow : PropTypes . func ,
53
54
onDropdownWillHide : PropTypes . func ,
@@ -84,8 +85,8 @@ export default class ModalDropdown extends Component {
84
85
}
85
86
86
87
componentWillReceiveProps ( nextProps ) {
87
- var buttonText = this . _nextValue == null ? this . state . buttonText : this . _nextValue . toString ( ) ;
88
- var selectedIndex = this . _nextIndex == null ? this . state . selectedIndex : this . _nextIndex ;
88
+ let buttonText = this . _nextValue == null ? this . state . buttonText : this . _nextValue . toString ( ) ;
89
+ let selectedIndex = this . _nextIndex == null ? this . state . selectedIndex : this . _nextIndex ;
89
90
if ( selectedIndex < 0 ) {
90
91
selectedIndex = nextProps . defaultIndex ;
91
92
if ( selectedIndex < 0 ) {
@@ -136,7 +137,7 @@ export default class ModalDropdown extends Component {
136
137
}
137
138
138
139
select ( idx ) {
139
- var value = this . props . defaultValue ;
140
+ let value = this . props . defaultValue ;
140
141
if ( idx == null || this . props . options == null || idx >= this . props . options . length ) {
141
142
idx = this . props . defaultIndex ;
142
143
}
@@ -184,8 +185,8 @@ export default class ModalDropdown extends Component {
184
185
185
186
_renderModal ( ) {
186
187
if ( this . state . showDropdown && this . _buttonFrame ) {
187
- let frameStyle = this . _calcPosition ( ) ;
188
- let animationType = this . props . animated ? 'fade' : 'none' ;
188
+ const frameStyle = this . _calcPosition ( ) ;
189
+ const animationType = this . props . animated ? 'fade' : 'none' ;
189
190
return (
190
191
< Modal animationType = { animationType }
191
192
visible = { true }
@@ -207,27 +208,27 @@ export default class ModalDropdown extends Component {
207
208
}
208
209
209
210
_calcPosition ( ) {
210
- let dimensions = Dimensions . get ( 'window' ) ;
211
- let windowWidth = dimensions . width ;
212
- let windowHeight = dimensions . height ;
211
+ const dimensions = Dimensions . get ( 'window' ) ;
212
+ const windowWidth = dimensions . width ;
213
+ const windowHeight = dimensions . height ;
213
214
214
- let dropdownHeight = ( this . props . dropdownStyle && StyleSheet . flatten ( this . props . dropdownStyle ) . height ) ||
215
+ const dropdownHeight = ( this . props . dropdownStyle && StyleSheet . flatten ( this . props . dropdownStyle ) . height ) ||
215
216
StyleSheet . flatten ( styles . dropdown ) . height ;
216
217
217
- let bottomSpace = windowHeight - this . _buttonFrame . y - this . _buttonFrame . h ;
218
- let rightSpace = windowWidth - this . _buttonFrame . x ;
219
- let showInBottom = bottomSpace >= dropdownHeight || bottomSpace >= this . _buttonFrame . y ;
220
- let showInLeft = rightSpace >= this . _buttonFrame . x ;
218
+ const bottomSpace = windowHeight - this . _buttonFrame . y - this . _buttonFrame . h ;
219
+ const rightSpace = windowWidth - this . _buttonFrame . x ;
220
+ const showInBottom = bottomSpace >= dropdownHeight || bottomSpace >= this . _buttonFrame . y ;
221
+ const showInLeft = rightSpace >= this . _buttonFrame . x ;
221
222
222
- var style = {
223
+ let style = {
223
224
height : dropdownHeight ,
224
225
top : showInBottom ? this . _buttonFrame . y + this . _buttonFrame . h : Math . max ( 0 , this . _buttonFrame . y - dropdownHeight ) ,
225
226
} ;
226
227
227
228
if ( showInLeft ) {
228
229
style . left = this . _buttonFrame . x ;
229
230
} else {
230
- let dropdownWidth = ( this . props . dropdownStyle && StyleSheet . flatten ( this . props . dropdownStyle ) . width ) ||
231
+ const dropdownWidth = ( this . props . dropdownStyle && StyleSheet . flatten ( this . props . dropdownStyle ) . width ) ||
231
232
( this . props . style && StyleSheet . flatten ( this . props . style ) . width ) || - 1 ;
232
233
if ( dropdownWidth !== - 1 ) {
233
234
style . width = dropdownWidth ;
@@ -277,16 +278,16 @@ export default class ModalDropdown extends Component {
277
278
}
278
279
279
280
get _dataSource ( ) {
280
- let ds = new ListView . DataSource ( {
281
+ const ds = new ListView . DataSource ( {
281
282
rowHasChanged : ( r1 , r2 ) => r1 !== r2
282
283
} ) ;
283
284
return ds . cloneWithRows ( this . props . options ) ;
284
285
}
285
286
286
287
_renderRow ( rowData , sectionID , rowID , highlightRow ) {
287
- let key = `row_${ rowID } ` ;
288
- let highlighted = rowID == this . state . selectedIndex ;
289
- let row = ! this . props . renderRow ?
288
+ const key = `row_${ rowID } ` ;
289
+ const highlighted = rowID == this . state . selectedIndex ;
290
+ const row = ! this . props . renderRow ?
290
291
( < Text style = { [
291
292
styles . rowText ,
292
293
this . props . dropdownTextStyle ,
@@ -297,13 +298,13 @@ export default class ModalDropdown extends Component {
297
298
{ rowData }
298
299
</ Text > ) :
299
300
this . props . renderRow ( rowData , rowID , highlighted ) ;
300
- let preservedProps = {
301
+ const preservedProps = {
301
302
key : key ,
302
303
accessible : this . props . accessible ,
303
304
onPress : ( ) => this . _onRowPress ( rowData , sectionID , rowID , highlightRow ) ,
304
305
} ;
305
306
if ( TOUCHABLE_ELEMENTS . find ( name => name == row . type . displayName ) ) {
306
- var props = { ...row . props } ;
307
+ const props = { ...row . props } ;
307
308
props . key = preservedProps . key ;
308
309
props . onPress = preservedProps . onPress ;
309
310
switch ( row . type . displayName ) {
@@ -315,7 +316,6 @@ export default class ModalDropdown extends Component {
315
316
</ TouchableHighlight >
316
317
) ;
317
318
}
318
- break ;
319
319
case 'TouchableOpacity' :
320
320
{
321
321
return (
@@ -324,7 +324,6 @@ export default class ModalDropdown extends Component {
324
324
</ TouchableOpacity >
325
325
) ;
326
326
}
327
- break ;
328
327
case 'TouchableWithoutFeedback' :
329
328
{
330
329
return (
@@ -333,7 +332,6 @@ export default class ModalDropdown extends Component {
333
332
</ TouchableWithoutFeedback >
334
333
) ;
335
334
}
336
- break ;
337
335
case 'TouchableNativeFeedback' :
338
336
{
339
337
return (
@@ -342,7 +340,6 @@ export default class ModalDropdown extends Component {
342
340
</ TouchableNativeFeedback >
343
341
) ;
344
342
}
345
- break ;
346
343
default :
347
344
break ;
348
345
}
@@ -355,26 +352,25 @@ export default class ModalDropdown extends Component {
355
352
}
356
353
357
354
_onRowPress ( rowData , sectionID , rowID , highlightRow ) {
358
- if ( ! this . props . onSelect ||
359
- this . props . onSelect ( rowID , rowData ) !== false ) {
355
+ const { onSelect , renderButtonText , onDropdownWillHide } = this . props ;
356
+ if ( ! onSelect || onSelect ( rowID , rowData ) !== false ) {
360
357
highlightRow ( sectionID , rowID ) ;
361
358
this . _nextValue = rowData ;
362
359
this . _nextIndex = rowID ;
363
360
this . setState ( {
364
- buttonText : rowData . toString ( ) ,
361
+ buttonText : renderButtonText && renderButtonText ( rowData ) || rowData . toString ( ) ,
365
362
selectedIndex : rowID
366
363
} ) ;
367
364
}
368
- if ( ! this . props . onDropdownWillHide ||
369
- this . props . onDropdownWillHide ( ) !== false ) {
365
+ if ( ! onDropdownWillHide || onDropdownWillHide ( ) !== false ) {
370
366
this . setState ( {
371
367
showDropdown : false
372
368
} ) ;
373
369
}
374
370
}
375
371
376
372
_renderSeparator ( sectionID , rowID , adjacentRowHighlighted ) {
377
- let key = `spr_${ rowID } ` ;
373
+ const key = `spr_${ rowID } ` ;
378
374
return ( < View style = { styles . separator }
379
375
key = { key }
380
376
/> ) ;
0 commit comments