react-native-wheely
react-native-wheely copied to clipboard
a new selectedIndex makes the view to disappear
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
I try to investigate a bit and apparently setting the
animatedoption to true inside thescrollToIndexmethods 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.
the scrollToIndex is inside the wheel component and it is called when a new selectedIndex is provided
@Francesco-Voto Hi, try to remove
initialScrollIndex={selectedIndex}
from component.