Skip to content

Conversation

@raketeFlo
Copy link

This allows to programmatically open the picker on android devices.

See open Issue.

@PavelTishenko
Copy link

Any updates ? ) We need it !

@indapublic
Copy link

Needed feature here, but @JoFlo07 you have broken tests in your PR

@raketeFlo
Copy link
Author

I had a look into it and it seems like the failure of the test is related to the jest.config of these tests not to the changes I made. Can you guys have a look at your test suite?

@andrejpavlovic
Copy link

Patch based on this PR here:

diff --git a/node_modules/react-native-picker-select/src/index.js b/node_modules/react-native-picker-select/src/index.js
index 7ae6730..da08215 100644
--- a/node_modules/react-native-picker-select/src/index.js
+++ b/node_modules/react-native-picker-select/src/index.js
@@ -253,6 +253,14 @@ export default class RNPickerSelect extends PureComponent {
       Keyboard.dismiss();
     }
 
+    if (this.pickerRef && Platform.OS === 'android') {
+      if (!showPicker) {
+        this.pickerRef.focus();
+      } else {
+        this.pickerRef.blur();
+      }
+    }
+
     const animationType =
       modalProps && modalProps.animationType ? modalProps.animationType : 'slide';
 
@@ -511,6 +519,7 @@ export default class RNPickerSelect extends PureComponent {
         <View style={style.headlessAndroidContainer}>
           {this.renderTextInputOrChildren()}
           <Picker
+            ref={(ref) => {this.pickerRef = ref}}
             style={[
               Icon ? { backgroundColor: 'transparent' } : {}, // to hide native icon
               defaultStyles.headlessAndroidPicker,
@@ -536,6 +545,7 @@ export default class RNPickerSelect extends PureComponent {
     return (
       <View style={[defaultStyles.viewContainer, style.viewContainer]}>
         <Picker
+          ref={(ref) => {this.pickerRef = ref}}
           style={[
             Icon ? { backgroundColor: 'transparent' } : {}, // to hide native icon
             style.inputAndroid,

Comment on lines +251 to +253
if (this.pickerRef && Platform.OS == 'android') {
this.pickerRef.focus();
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should take into account whether picker is currently visible or not.

Suggested change
if (this.pickerRef && Platform.OS == 'android') {
this.pickerRef.focus();
};
if (this.pickerRef && Platform.OS === 'android') {
if (!showPicker) {
this.pickerRef.focus();
} else {
this.pickerRef.blur();
}
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this didn't work, using only this.pickerRef.focus() did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants