react-native-wheely icon indicating copy to clipboard operation
react-native-wheely copied to clipboard

a new selectedIndex makes the view to disappear

Open Francesco-Voto opened this issue 2 years ago • 6 comments

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

Francesco-Voto avatar Oct 26 '23 07:10 Francesco-Voto

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.

mmkthecoolest avatar Nov 03 '23 14:11 mmkthecoolest

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

Francesco-Voto avatar Nov 03 '23 14:11 Francesco-Voto

@Francesco-Voto Hi, try to remove

initialScrollIndex={selectedIndex}

from component.

lorenc-tomasz avatar Jan 15 '24 07:01 lorenc-tomasz