erksch / react-native-wheely

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

selectedIndex cannot be reselected #66

Closed Joaquim-Frances closed 9 months ago

Joaquim-Frances commented 9 months ago

Hi! I'm facing an issue that the selectedIndex disapears from the selction once we scroll up or down. For example if the selctedIndex is 0 you can scroll up or down but the index 0 will never appear again, you can see the option in the screen but the index is not in onChange.

<WheelPicker selectedIndex={0} options={timeTypesArray} onChange={(index) => { console.log({ index }); setTimeType(timeTypesArray[index]); }} itemHeight={35} containerStyle={{ backgroundColor: globalStyles.backgroundColor, width: "35%", }} itemStyle={{ backgroundColor: "transparent" }} itemTextStyle={{ color: "white", fontSize: 18, fontFamily: "Montserrat_300Light", }} selectedIndicatorStyle={{ backgroundColor: globalStyles.backgroundColorTwo, }} visibleRest={1} />

Joaquim-Frances commented 9 months ago

I found a workaround comparing the values of my state:

selectedIndex={ timeType === "seconds" ? 0 : timeType === "minutes" ? 1 : 2 }

Joaquim-Frances commented 9 months ago

Nevermind, I was using wrongly the selectedIndex