Comments (14)
I have got the similar issue with any items.
the picker will auto select the first item by default.
thus when user choose the first item, onValueChange() will NOT be called.
any options to disable "select the first item by default"?
from picker.
onValueChange needs the value to be changed, so if there is just one item it will be selected automatically, so when selecting it the onValueChange will never be called,
i am facing a similar issue when i reselect the same item,
we need a new props like onValueSelected, that's would be general
from picker.
We were able to somewhat work around this issue on my current project by inserting an option at the top of the list of options and using it as the picker prompt instead of using the androidPrompt
prop on Picker
. We style that option with a bigger font size to distinguish it as a header. This option has a bogus value
, and we ignore this value in onValueChange
if the option was selected.
<Picker
selectedValue={selectedValue}
onValueChange={(value) => {
if (value !== EMPTY_LABEL_VALUE) {
onChange(value);
}
}}
>
<Picker.Item
label={androidPrompt}
value={EMPTY_LABEL_VALUE}
style={styles.pickerAndroidPrompt}
/>
{options.map((option) => (
<Picker.Item
key={option.value}
label={option.label}
value={option.value}
style={styles.pickerAndroidItem}
/>
))}
</Picker>
Minor notes:
- Styling the first option with font weight did not work
- When we set the font size for the first option, there were some weird issues where other options randomly had the larger font. To work around that, we had to explicitly set the font size in the other options
from picker.
+1
from picker.
Same for iOS. However, it is possible to scroll up, then down and select an option because of the scroll bouncing
from picker.
Hey, guys, have you found any workaround for this? I'm also facing a situation when onValueChange
is not called for the first item
from picker.
Hi @Naturalclar, do you know is there a way to avoid this bug besides explicitly setting the first item as a default value? If I get it right from the source code the problem comes from native android picker
from picker.
Having the same issue as @DnEgorWeb . Did you guys find a solution for this?
If not, I would proceed with adding the first item with a placeholder label that has as value the 'undefined' string. That appears to be working:
<Picker.Item label={'--None--'} value={'undefined'}/>
from picker.
On my case, I have forms with Pickers not required, so the user could leave them empty... So if they choose an item, they could need to clear the picker after that so I'm adding this before items
<Picker.Item label={''} value={''} />
and works perfectly for me
from picker.
I believe this could be fix on Android, but need quite some effort
Had a quick look at the implementation:
At this line here, the native event with
position
value -1
should be emitted for our JS control component to handle, in case of no value selected or picker has no option items?
But neither setting selectedValue={undefined}
nor giving to Picker.Item
will trigger onNothingSelected
callback.
If the owner may provide some guidance, I am down for helping with this.
Another related point to note is that for AdapterView.onItemSelected
This callback is invoked only when the newly selected position is different from the previously selected position or if there was no selected item.
Is it possible to use AdapterView.OnItemClickListener
instead to have more picker control ?
@Naturalclar
from picker.
Same issue. Did you guys find a solution for this?
from picker.
Same issue. Did you guys find a solution for this?
from picker.
Same issue. Did you guys find a solution for this?
from picker.
This is still a big issue. onValueChange
isn't fired even when specifying selectedValue
to other than the first option's value. How is this not fixed?
My temporary fix is to add <Picker.Item enabled={false} />
as a first item but that looks awful.
from picker.
Related Issues (20)
- Picker 2.6+ transforms numeric values to strings HOT 4
- Selected value jumps back to first value when "Done" is tapped - Picker library v2.6.1, iOS only HOT 3
- @react-native-picker/picker could not be found within the project or in these directories
- react-native 0.71.8 with @react-native-picker/picker HOT 3
- can't remove gray background on IOS picker HOT 1
- On iOS, the value selected in onValueChange comes in null
- Picker Item is not listed on IOS HOT 10
- Border styles is not working HOT 2
- the problem of selectionColor HOT 3
- New version(2.7.0) compile time issue in android | Keeps app crashing HOT 3
- Facing Error when create debug app build: public record ReactPickerLocalData(int height) { ^ (use -source 16 or higher to enable records) HOT 4
- Error after npm run android HOT 2
- Run Android triggers Execution failed for task ':app:mergeLibDexDebug'
- how to disable font scaling of @react-native-picker/picker HOT 1
- Attempt to invoke interface method 'com.facebook.react.bridge.ReadableNativeMap com.facebook.react.uimanager.StateWrapper.getStateData()' on a null object reference HOT 2
- onValueChange callback has its arg only accepting string type now HOT 5
- enabled={false} not working on ios HOT 1
- Unable to close the selector without selecting item.
- Invariant Violation: requireNativeComponent: "RNCAndroidDialogPicker" was not found in the UIManager. HOT 2
- invariant Violation: requireNativeComponent: "RNCAndroidDialogPicker" was not found in the UIManager
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from picker.