-
Notifications
You must be signed in to change notification settings - Fork 499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/toggle picker android #462
base: master
Are you sure you want to change the base?
Conversation
Any updates ? ) We need it ! |
Needed feature here, but @JoFlo07 you have broken tests in your PR |
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? |
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, |
if (this.pickerRef && Platform.OS == 'android') { | ||
this.pickerRef.focus(); | ||
}; |
There was a problem hiding this comment.
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.
if (this.pickerRef && Platform.OS == 'android') { | |
this.pickerRef.focus(); | |
}; | |
if (this.pickerRef && Platform.OS === 'android') { | |
if (!showPicker) { | |
this.pickerRef.focus(); | |
} else { | |
this.pickerRef.blur(); | |
} | |
} |
This allows to programmatically open the picker on android devices.
See open Issue.