question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not showing selected value on Android

See original GitHub issue

Describe the bug
I am using picker-select in form for creating/editing notes. I am fetching items from our API.

First issue is with create note:

  • Open picker, can see all items
  • Select item
  • item label is not shown in select field
  • if i save note, it is created with correct category

Issue with edit:

  • click on edit
  • do not see label
  • can select different item, but after select, do not see label in field

It works fine only if i have items array locally ( not acceptable) and also default value is set to value from items, which is problem for creating new, because default is null. Also it is not accepting default value from props (as can be seen in code snipet)

On iPhone works just fine, only Android issue.

To Reproduce
Steps to reproduce the behavior:

  1. Go to ‘…’
  2. Click on ‘…’
  3. Scroll down to ‘…’
  4. See error

Expected behavior
I expected the same behavior as on iPhone.

Screenshots

  1. Empty new form
image
  1. Show all items
image
  1. Select picker after select one of the items
image

Additional details

  • Device: [Pixel 3]
  • OS: [Android 11]
  • react-native-picker-select version: [8.04]
  • react-native version: [0.63]
  • expo sdk version: [40]

Reproduction and/or code sample

function NewNote({ t, note: _note, loading, onSubmit, onCancel }) {
  const [note, setNote] = useState(_note);
  const [categories, setCategories] = useState([]);
  const [categoryId, setCategoryId] = (_note && _note.categoryId );

  const handleSubmit = async () => {
    await onSubmit(note);
    setNote(null);
    onCancel();
  };

  const loadCategories = async () => {
    const res = await axios('categories/autocompletes', {
      params: {
        params: { perPage: 9999 },
        filters: [
          {
            by: 'categoryType',
            rule: 'equal',
            value: 'Note'
          }
        ]
      }
    });

    setCategories(
      res.data.categories.map(c => ({
        value: c.id,
        label: c.name
      }))
    );
  };

  const handleNoteTypeChange = value => {
    if (!value) return;
    setCategoryId(value);
    setNote({ ...note, categoryId: value });
  };

  useEffect(() => {
    loadCategories();
  }, []);

  return (
           <RNPickerSelect
            value={note && note.categoryId}
            onValueChange={handleNoteTypeChange}
            style={_pickerStyles}
            placeholder={{ label: 'Type', value: null }}
            items={categories}
          />
)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:8
  • Comments:16

github_iconTop GitHub Comments

71reactions
iwashi1tcommented, Jan 22, 2021

As a temporary workaround, I found two solutions.

Set one of the following prop to RNPickerSelect,

  • style={{ inputAndroid: { color: 'black' } }}
  • useNativeAndroidPickerStyle={false}
4reactions
iggirexcommented, Feb 5, 2021

After many hours of twiddling with this thing finally found this thread. Low and behold this indeed does fix the problem!! style={{ inputAndroid: { color: 'black' } }} useNativeAndroidPickerStyle={false}

My other solution was to set the placeholder as empty object, but this screws up the layout if you’re needing that placeholder placeholder={{}}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spinner does not show selected value - Stack Overflow
Spinner displays neither the default nor selected item value. ... Write a custom layout for a spiner item and use it instead of...
Read more >
The HTML Option element - MDN Web Docs - Mozilla
The content of this attribute represents the value to be submitted with the form, should this option be selected. If this attribute is...
Read more >
ion-select: Select One or Multiple Value Boxes or Placeholders
ion-select is represented by selected value(s), or a placeholder, and dropdown icon. When you tap select, a dialog box appears with an easy...
Read more >
How to Set the Selected Item of Spinner By Value and Not By ...
Spinner is used in many android applications to display multiple options within a drop-down list and the user will be able to select...
Read more >
react-native-select-dropdown - npm
Start using react-native-select-dropdown in your project by running `npm i ... dropdown | select | picker | menu for react native that works...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found