react-native-select-dropdown
react-native-select-dropdown copied to clipboard
`scrollToIndex` error when set the default value over the certain index for a list over 41 items.
Hi,
I notice there is a bug when I try to set the defaultValue
to the 41th element in the data list.
This can be reproduced by the following code
const MySelection = () => {
const data = useMemo(() => {
let arr = []
for (let i = 0; i < 100; i++) {
arr.push(i.toString());
}
return arr;
}, [])
return <SelectDropdown
data={data}
onSelect={(selectedItem, index) => {
console.log(selectedItem, index);
}}
defaultValue={"40"}
renderButton={(selectedItem, isOpened) => (<View><Text>{selectedItem || 'Change me'}</Text></View>)}
renderItem={(item, index, isSelected) => (<View><Text>{item}</Text></View>)
}
showsVerticalScrollIndicator={true}
/>
};
This is the error page from the iPhone simulator.
Based on the error message, it seems like before running scrollToIndex
, there should be a getItemLayout
being used.
I am happy to open a PR to fix this if you preferred. Thanks