rdhox / react-native-smooth-picker

A smooth picker for react-native
MIT License
215 stars 27 forks source link

Uncontrolled movement with fast scrolling in horizontal mode release mode #22

Open CodeShiva87 opened 4 years ago

CodeShiva87 commented 4 years ago

I'm facing this issue only in release mode that the smooth picker moves uncontrollably in horizontal mode with fast scrolling. Not able to reproduce this in Debug mode and hence not able to solve it. Scrolling stops abruptly after some time or when I close the App and restart.

"react-native-smooth-picker": "^1.0.2",

 <SmoothPicker
   initialScrollToIndex={selected}
   refFlatList={refPicker}
   keyExtractor={(_, index) => index.toString()}
   horizontal={true}
   scrollAnimation
   showsHorizontalScrollIndicator={false}
   data={constants.MyArray}
   renderItem={option => ItemToRender(option, selected, false)}
   onSelected={({ item, index }) => handleChange(index)}
   style={{backgroundColor: 'white', paddingLeft: 5, paddingRight: 5}}
 />

function handleChange(index) {
    setSelected(index);
    refPicker.current.scrollToIndex({
      animated: true,
      index: index,
      viewOffset: -30,
    });
  }

const ItemToRender = ({item, index}, indexSelected, vertical) => {
  const selected = index === indexSelected;
  const gap = Math.abs(index - indexSelected);

  let opacity = opacities[gap];
  if (gap > 3) {
    opacity = opacities[4];
  }
  let fontSize = sizeText[gap];
  if (gap > 1) {
    fontSize = sizeText[2];
  }

  return <Item opacity={opacity} selected={selected} vertical={vertical} fontSize={fontSize} name={item}/>;
};
rdhox commented 4 years ago

Hi, I was not able to reproduce your bug in release mode, can you update a gif or more details? Try to use the latest version 1.1.3 also.

CodeShiva87 commented 4 years ago

Hi, I was not able to reproduce your bug in release mode, can you update a gif or more details? Try to use the latest version 1.1.3 also.

Thanks. Looks like the issue is in the code below in handleChange: refPicker.current.scrollToIndex({ animated: true, index: index, viewOffset: -30, });

Works fine when I remove this. Not sure why it doesn't work properly in Release mode though.