react-native-select-dropdown icon indicating copy to clipboard operation
react-native-select-dropdown copied to clipboard

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

Open PoHengLinTW opened this issue 1 year ago • 2 comments

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

PoHengLinTW avatar Apr 01 '24 04:04 PoHengLinTW

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

I removed it by mistake I will add it again

AdelRedaa97 avatar Apr 01 '24 11:04 AdelRedaa97

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

PoHengLinTW avatar Apr 01 '24 22:04 PoHengLinTW

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

naheedsa avatar Apr 09 '24 08:04 naheedsa

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

AdelRedaa97 avatar Apr 09 '24 12:04 AdelRedaa97