@@ -147,13 +147,13 @@ export default class RNPickerSelect extends PureComponent {
147
147
super ( props ) ;
148
148
149
149
const items = RNPickerSelect . handlePlaceholder ( {
150
- placeholder : this . props . placeholder ,
151
- } ) . concat ( this . props . items ) ;
150
+ placeholder : props . placeholder ,
151
+ } ) . concat ( props . items ) ;
152
152
153
153
const { selectedItem } = RNPickerSelect . getSelectedItem ( {
154
154
items,
155
- key : this . props . itemKey ,
156
- value : this . props . value ,
155
+ key : props . itemKey ,
156
+ value : props . value ,
157
157
} ) ;
158
158
159
159
this . state = {
@@ -170,7 +170,6 @@ export default class RNPickerSelect extends PureComponent {
170
170
this . onOrientationChange = this . onOrientationChange . bind ( this ) ;
171
171
this . setInputRef = this . setInputRef . bind ( this ) ;
172
172
this . togglePicker = this . togglePicker . bind ( this ) ;
173
- this . triggerDoneCallback = this . triggerDoneCallback . bind ( this ) ;
174
173
this . renderInputAccessoryView = this . renderInputAccessoryView . bind ( this ) ;
175
174
}
176
175
@@ -210,8 +209,9 @@ export default class RNPickerSelect extends PureComponent {
210
209
211
210
getPlaceholderStyle ( ) {
212
211
const { placeholder, placeholderTextColor, style } = this . props ;
212
+ const { selectedItem } = this . state ;
213
213
214
- if ( ! isEqual ( placeholder , { } ) && this . state . selectedItem . label === placeholder . label ) {
214
+ if ( ! isEqual ( placeholder , { } ) && selectedItem . label === placeholder . label ) {
215
215
return {
216
216
...defaultStyles . placeholder ,
217
217
color : placeholderTextColor , // deprecated
@@ -223,31 +223,26 @@ export default class RNPickerSelect extends PureComponent {
223
223
224
224
triggerOpenCloseCallbacks ( ) {
225
225
const { onOpen, onClose } = this . props ;
226
+ const { showPicker } = this . state ;
226
227
227
- if ( ! this . state . showPicker && onOpen ) {
228
+ if ( ! showPicker && onOpen ) {
228
229
onOpen ( ) ;
229
230
}
230
231
231
- if ( this . state . showPicker && onClose ) {
232
+ if ( showPicker && onClose ) {
232
233
onClose ( ) ;
233
234
}
234
235
}
235
236
236
- triggerDoneCallback ( ) {
237
- const { hideDoneBar, onDonePress } = this . props ;
238
- if ( ! hideDoneBar && onDonePress ) {
239
- onDonePress ( ) ;
240
- }
241
- }
242
-
243
237
togglePicker ( animate = false , postToggleCallback ) {
244
238
const { modalProps, disabled } = this . props ;
239
+ const { showPicker } = this . state ;
245
240
246
241
if ( disabled ) {
247
242
return ;
248
243
}
249
244
250
- if ( ! this . state . showPicker ) {
245
+ if ( ! showPicker ) {
251
246
Keyboard . dismiss ( ) ;
252
247
}
253
248
@@ -272,7 +267,9 @@ export default class RNPickerSelect extends PureComponent {
272
267
}
273
268
274
269
renderPickerItems ( ) {
275
- return this . state . items . map ( ( item ) => {
270
+ const { items } = this . state ;
271
+
272
+ return items . map ( ( item ) => {
276
273
return (
277
274
< Picker . Item
278
275
label = { item . label }
@@ -291,6 +288,7 @@ export default class RNPickerSelect extends PureComponent {
291
288
hideDoneBar,
292
289
onUpArrow,
293
290
onDownArrow,
291
+ onDonePress,
294
292
style,
295
293
} = this . props ;
296
294
@@ -342,13 +340,15 @@ export default class RNPickerSelect extends PureComponent {
342
340
</ View >
343
341
< TouchableWithoutFeedback
344
342
onPress = { ( ) => {
345
- this . togglePicker ( true ) ;
343
+ this . togglePicker ( true , onDonePress ) ;
346
344
} }
347
345
hitSlop = { { top : 4 , right : 4 , bottom : 4 , left : 4 } }
348
346
testID = "done_button"
349
347
>
350
348
< View testID = "needed_for_touchable" >
351
- < Text style = { [ defaultStyles . done , style . done ] } > { doneText } </ Text >
349
+ < Text allowFontScaling = { false } style = { [ defaultStyles . done , style . done ] } >
350
+ { doneText }
351
+ </ Text >
352
352
</ View >
353
353
</ TouchableWithoutFeedback >
354
354
</ View >
@@ -374,6 +374,8 @@ export default class RNPickerSelect extends PureComponent {
374
374
375
375
renderTextInputOrChildren ( ) {
376
376
const { children, style, textInputProps } = this . props ;
377
+ const { selectedItem } = this . state ;
378
+
377
379
const containerStyle =
378
380
Platform . OS === 'ios' ? style . inputIOSContainer : style . inputAndroidContainer ;
379
381
@@ -392,7 +394,7 @@ export default class RNPickerSelect extends PureComponent {
392
394
Platform . OS === 'ios' ? style . inputIOS : style . inputAndroid ,
393
395
this . getPlaceholderStyle ( ) ,
394
396
] }
395
- value = { this . state . selectedItem . label }
397
+ value = { selectedItem . label }
396
398
ref = { this . setInputRef }
397
399
editable = { false }
398
400
{ ...textInputProps }
@@ -404,6 +406,7 @@ export default class RNPickerSelect extends PureComponent {
404
406
405
407
renderIOS ( ) {
406
408
const { style, modalProps, pickerProps } = this . props ;
409
+ const { animationType, orientation, selectedItem, showPicker } = this . state ;
407
410
408
411
return (
409
412
< View style = { [ defaultStyles . viewContainer , style . viewContainer ] } >
@@ -417,11 +420,10 @@ export default class RNPickerSelect extends PureComponent {
417
420
</ TouchableWithoutFeedback >
418
421
< Modal
419
422
testID = "ios_modal"
420
- visible = { this . state . showPicker }
423
+ visible = { showPicker }
421
424
transparent
422
- animationType = { this . state . animationType }
425
+ animationType = { animationType }
423
426
supportedOrientations = { [ 'portrait' , 'landscape' ] }
424
- onDismiss = { this . triggerDoneCallback }
425
427
onOrientationChange = { this . onOrientationChange }
426
428
{ ...modalProps }
427
429
>
@@ -436,14 +438,14 @@ export default class RNPickerSelect extends PureComponent {
436
438
< View
437
439
style = { [
438
440
defaultStyles . modalViewBottom ,
439
- { height : this . state . orientation === 'portrait' ? 215 : 162 } ,
441
+ { height : orientation === 'portrait' ? 215 : 162 } ,
440
442
style . modalViewBottom ,
441
443
] }
442
444
>
443
445
< Picker
444
446
testID = "ios_picker"
445
447
onValueChange = { this . onValueChange }
446
- selectedValue = { this . state . selectedItem . value }
448
+ selectedValue = { selectedItem . value }
447
449
{ ...pickerProps }
448
450
>
449
451
{ this . renderPickerItems ( ) }
@@ -456,6 +458,7 @@ export default class RNPickerSelect extends PureComponent {
456
458
457
459
renderAndroidHeadless ( ) {
458
460
const { disabled, Icon, style, pickerProps } = this . props ;
461
+ const { selectedItem } = this . state ;
459
462
460
463
return (
461
464
< View style = { style . headlessAndroidContainer } >
@@ -469,7 +472,7 @@ export default class RNPickerSelect extends PureComponent {
469
472
testID = "android_picker_headless"
470
473
enabled = { ! disabled }
471
474
onValueChange = { this . onValueChange }
472
- selectedValue = { this . state . selectedItem . value }
475
+ selectedValue = { selectedItem . value }
473
476
{ ...pickerProps }
474
477
>
475
478
{ this . renderPickerItems ( ) }
@@ -480,6 +483,7 @@ export default class RNPickerSelect extends PureComponent {
480
483
481
484
renderAndroidNativePickerStyle ( ) {
482
485
const { disabled, Icon, style, pickerProps } = this . props ;
486
+ const { selectedItem } = this . state ;
483
487
484
488
return (
485
489
< View style = { [ defaultStyles . viewContainer , style . viewContainer ] } >
@@ -492,7 +496,7 @@ export default class RNPickerSelect extends PureComponent {
492
496
testID = "android_picker"
493
497
enabled = { ! disabled }
494
498
onValueChange = { this . onValueChange }
495
- selectedValue = { this . state . selectedItem . value }
499
+ selectedValue = { selectedItem . value }
496
500
{ ...pickerProps }
497
501
>
498
502
{ this . renderPickerItems ( ) }
0 commit comments