@@ -10,9 +10,9 @@ import { Dimensions } from 'react-native';
10
10
// This height was tested thoroughly on several iPhone Models (from iPhone 8 to 14 Pro)
11
11
const IOS_MODAL_HEIGHT = 262 ;
12
12
13
- const preserveSpaces = ( label ) => {
13
+ const preserveSpaces = ( label ) => {
14
14
return label . replace ( / / g, '\u00a0' ) ;
15
- }
15
+ } ;
16
16
17
17
export default class RNPickerSelect extends PureComponent {
18
18
static propTypes = {
@@ -151,6 +151,7 @@ export default class RNPickerSelect extends PureComponent {
151
151
this . scrollToInput = this . scrollToInput . bind ( this ) ;
152
152
this . togglePicker = this . togglePicker . bind ( this ) ;
153
153
this . renderInputAccessoryView = this . renderInputAccessoryView . bind ( this ) ;
154
+ this . updatePickerState = this . updatePickerState . bind ( this ) ;
154
155
}
155
156
156
157
componentDidUpdate = ( prevProps , prevState ) => {
@@ -264,23 +265,10 @@ export default class RNPickerSelect extends PureComponent {
264
265
}
265
266
}
266
267
267
- togglePicker ( animate = false , postToggleCallback ) {
268
- const { modalProps, disabled } = this . props ;
269
- const { showPicker } = this . state ;
270
-
271
- if ( disabled ) {
272
- return ;
273
- }
274
-
275
- if ( ! showPicker ) {
276
- Keyboard . dismiss ( ) ;
277
- }
278
-
268
+ updatePickerState = ( animate = false , postToggleCallback ) => {
269
+ const { modalProps } = this . props ;
279
270
const animationType =
280
271
modalProps && modalProps . animationType ? modalProps . animationType : 'slide' ;
281
-
282
- this . triggerOpenCloseCallbacks ( ) ;
283
-
284
272
this . setState (
285
273
( prevState ) => {
286
274
return {
@@ -294,6 +282,26 @@ export default class RNPickerSelect extends PureComponent {
294
282
}
295
283
}
296
284
) ;
285
+ } ;
286
+
287
+ togglePicker ( animate = false , postToggleCallback ) {
288
+ const { disabled } = this . props ;
289
+
290
+ if ( disabled ) {
291
+ return ;
292
+ }
293
+
294
+ this . triggerOpenCloseCallbacks ( ) ;
295
+
296
+ if ( Keyboard . isVisible ( ) ) {
297
+ const keyboardListener = Keyboard . addListener ( 'keyboardDidHide' , ( ) => {
298
+ this . updatePickerState ( animate , postToggleCallback ) ;
299
+ keyboardListener . remove ( ) ;
300
+ } ) ;
301
+ Keyboard . dismiss ( ) ;
302
+ } else {
303
+ this . updatePickerState ( animate , postToggleCallback ) ;
304
+ }
297
305
}
298
306
299
307
renderPickerItems ( ) {
0 commit comments