@@ -10,9 +10,9 @@ import { Dimensions } from 'react-native';
1010// This height was tested thoroughly on several iPhone Models (from iPhone 8 to 14 Pro)
1111const IOS_MODAL_HEIGHT = 262 ;
1212
13- const preserveSpaces = ( label ) => {
13+ const preserveSpaces = ( label ) => {
1414 return label . replace ( / / g, '\u00a0' ) ;
15- }
15+ } ;
1616
1717export default class RNPickerSelect extends PureComponent {
1818 static propTypes = {
@@ -151,6 +151,7 @@ export default class RNPickerSelect extends PureComponent {
151151 this . scrollToInput = this . scrollToInput . bind ( this ) ;
152152 this . togglePicker = this . togglePicker . bind ( this ) ;
153153 this . renderInputAccessoryView = this . renderInputAccessoryView . bind ( this ) ;
154+ this . updatePickerState = this . updatePickerState . bind ( this ) ;
154155 }
155156
156157 componentDidUpdate = ( prevProps , prevState ) => {
@@ -264,23 +265,10 @@ export default class RNPickerSelect extends PureComponent {
264265 }
265266 }
266267
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 ;
279270 const animationType =
280271 modalProps && modalProps . animationType ? modalProps . animationType : 'slide' ;
281-
282- this . triggerOpenCloseCallbacks ( ) ;
283-
284272 this . setState (
285273 ( prevState ) => {
286274 return {
@@ -294,6 +282,26 @@ export default class RNPickerSelect extends PureComponent {
294282 }
295283 }
296284 ) ;
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+ }
297305 }
298306
299307 renderPickerItems ( ) {
0 commit comments