erksch / react-native-wheely

An all JavaScript wheel picker for react-native without any native code.
409 stars 59 forks source link

a new selectedIndex makes the view to disappear #64

Open Francesco-Voto opened 10 months ago

Francesco-Voto commented 10 months ago

Hello,

I started to use this library, everything works fine until I need to set a selectedIndex.

Here the code:

  const [selectedIndex, setSelectedIndex] = useState(10)
  const {t} = useTranslation('account')

  const options = useRef(
    Array.from(
      {length: MAX_WEEK - MIN_WEEK + 1},
      (_, index) => `${t('changeYourPregnancyWeek.week')} ${index + MIN_WEEK}`
    )
  )

  const onChangeOption = useCallback((index: number) => {
    setSelectedIndex(index)
  }, [])

  return (
    <WheelPicker
      selectedIndex={selectedIndex}
      options={options.current}
      onChange={onChangeOption}
    />
  )
}

What happens is:

https://github.com/erksch/react-native-wheely/assets/8778613/85106032-01f1-4f41-904d-6c34e2d77b35

It happens for me on both platform.

I try to investigate a bit and apparently setting the animated option to true inside the scrollToIndex methods fixes the problem

mmkthecoolest commented 10 months ago

I try to investigate a bit and apparently setting the animated option to true inside the scrollToIndex methods fixes the problem

@Francesco-Voto What do you mean by scrollToIndex? I cannot find this in the README of the repo or in the code you posted, but I am also facing a similar issue on my Samsung, but not on emulator (likely due to a Samsung software update) and am wondering how to fix it.

Francesco-Voto commented 10 months ago

the scrollToIndex is inside the wheel component and it is called when a new selectedIndex is provided

mmkthecoolest commented 10 months ago

Oh it's a FlatList method

lorenc-tomasz commented 7 months ago

@Francesco-Voto Hi, try to remove

initialScrollIndex={selectedIndex}

from component.