Coder Social home page Coder Social logo

Comments (14)

bill2004158 avatar bill2004158 commented on August 15, 2024 7

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.

wissemContractor avatar wissemContractor commented on August 15, 2024 2

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.

stevehanson avatar stevehanson commented on August 15, 2024 1

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.

orzhtml avatar orzhtml commented on August 15, 2024

+1

from picker.

CyxouD avatar CyxouD commented on August 15, 2024

Same for iOS. However, it is possible to scroll up, then down and select an option because of the scroll bouncing

from picker.

DnEgorWeb avatar DnEgorWeb commented on August 15, 2024

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.

DnEgorWeb avatar DnEgorWeb commented on August 15, 2024

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.

villanuevadani avatar villanuevadani commented on August 15, 2024

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.

ayozebarrera avatar ayozebarrera commented on August 15, 2024

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.

Roytangrb avatar Roytangrb commented on August 15, 2024

I believe this could be fix on Android, but need quite some effort

Had a quick look at the implementation:

public void onNothingSelected(AdapterView<?> parent) {

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.

v-kryuchkov avatar v-kryuchkov commented on August 15, 2024

Same issue. Did you guys find a solution for this?

from picker.

marlti7 avatar marlti7 commented on August 15, 2024

Same issue. Did you guys find a solution for this?

from picker.

csamet07 avatar csamet07 commented on August 15, 2024

Same issue. Did you guys find a solution for this?

from picker.

Livijn avatar Livijn commented on August 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.