react-native-picker / picker

Picker is a cross-platform UI component for selecting an item from a list of options.
MIT License
1.53k stars 291 forks source link

onValueChange will trigger if I just moved the picker but didn't change the value #141

Open chj-damon opened 4 years ago

chj-damon commented 4 years ago

Bug report

Summary

I'm using react-naitve-picker in my project and I find that onValueChange will trigger multiple times on IOS even though I just move the picker slightly and didn't change the value.

<Picker
   data={[
     { label: 'zhangsan', value: 1 },
     { label: '1111', value: 2 },
     { label: '2222', value: 3 },
     { label: '3333', value: 4 },
     { label: '4444', value: 5 },
  ]}
  selectedValue={3}
  onValueChange={value => console.log('aaaa', value)}
/>

Picker.js

import { PickerIOS } from '@react-native-community/picker';

const { data = [], onValueChange, ...restProps } = props;
const handleChange = (selectedValue: ItemValue) => {
  if (onValueChange) {
    onValueChange(selectedValue);
  }
};

return (
    <PickerIOS {...restProps} onValueChange={handleChange}>
       {data.map((item) => (
          <PickerIOS.Item key={item.value} {...item} />
       ))}
    </PickerIOS>
)

2020-09-15 19-22-21 2020-09-15 19_25_54

Environment info

react-native info output:

react-native: v0.63.2

Library version: 1.7.1

Steps to reproduce

Describe what you expected to happen:

Reproducible sample code

EliasGcf commented 4 years ago

I have the same issue here, on Android.

tayzarmein commented 4 years ago

I have the same issue with expo SDK 38, on Android.

Balazs-D commented 3 years ago

Is there any update on this topic? This makes some weird issues for me since the picker in a modal and on each scroll the state is updated and the modal closes. This makes the UX bad.