AdelRedaa97 / react-native-select-dropdown

react-native-select-dropdown is a highly customized dropdown | select | picker | menu for react native that works for andriod and iOS platforms.
MIT License
312 stars 133 forks source link

`scrollToIndex` error when set the default value over the certain index for a list over 41 items. #182

Closed PoHengLinTW closed 3 months ago

PoHengLinTW commented 3 months ago

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

AdelRedaa97 commented 3 months ago

https://github.com/AdelRedaa97/react-native-select-dropdown/commit/6bafb535d006e8bbdffc26bb2755acaba9067a07#r140439325

I removed it by mistake I will add it again

PoHengLinTW commented 3 months ago

Sounds great, also noticed that comments here seem wrong to the functions (just need to exchange them.)

naheedsa commented 3 months ago

@AdelRedaa97 , Hello, is this updated yet? I still get this error

AdelRedaa97 commented 3 months ago

yes, Just fixed in v 4.0.1 try it and reopen the issue if its still existed