hossein-zare / react-native-dropdown-picker

A single / multiple, categorizable, customizable, localizable and searchable item picker (drop-down) component for react native which supports both Android & iOS.
https://hossein-zare.github.io/react-native-dropdown-picker-website/
MIT License
970 stars 294 forks source link

Want dropdown open up to last selected item when re-opening #660

Closed hamzah-shah closed 1 year ago

hamzah-shah commented 1 year ago

Let's say I select a value in the dropdown, close the dropdown, and reopen it. When I reopen it, the proper value is still selected, but the dropdown opens up to the top of the items list. Is there a way to make the dropdown open to the last selected item?

For example, if there's a dropdown counter with values 1-30, and the user selects 15. When they reopen the dropdown, it's much nicer if it opens up to 15 than if it opens up back to 1 and they have to scroll all the way.

Thanks!

TomasSestak commented 1 year ago

https://hossein-zare.github.io/react-native-dropdown-picker-website/docs/usage#autoscroll

hamzah-shah commented 1 year ago

Ah missed that, thanks! I'm noticing though that the auto-scroll only works for ~30 items. If I select an item above 30 in my dropdown, then it just scrolls until 30 and stops; it doesn't scroll all the way down to the selected item. For anything less than 30, it works fine. Any idea what could be going wrong?

TomasSestak commented 1 year ago

If you're using Flatlist mode, maybe making initialNumToRender or windowSize higher?

hamzah-shah commented 1 year ago

Worked! Thanks a ton! For anyone else who runs into this, the following inside the DropdownPicker component worked:

autoScroll={true} listMode="FLATLIST" flatListProps={{ initialNumToRender: X, windowSize: Y }}