hoaphantn7604 / react-native-element-dropdown

A react-native dropdown component easy to customize for both iOS and Android.
MIT License
1.02k stars 173 forks source link

Invariant Violation: scrollToIndex out of range: requested index 28 is out of 0 to 1, js engine: hermes #275

Open ds-shubhamsharma opened 6 months ago

gabrielroodriz commented 6 months ago

I solved this inside the Dropdows.tsx Index file

const scrollIndex = useCallback(() => {
  if (autoScroll && data.length > 0 && listData?.length === data?.length) {
    setTimeout(() => {
      if (refList && refList?.current) {
        const defaultValue = typeof value === 'object' ? _.get(value, valueField) : value;

        const index = _.findIndex(listData, (e) => _.isEqual(defaultValue, _.get(e, valueField)));

        if (index > -1 && index < listData.length) {
          try {
            refList.current.scrollToIndex({
              index: index,
              animated: false,
            });
          } catch (error) {
            console.warn(`scrollToIndex error: ${error.message}`);
          }
        } else {
          console.warn(`scrollToIndex out of range: requested index ${index} is out of 0 to ${listData.length - 1}`);
        }
      }
    }, 200);
  }
}, [autoScroll, data.length, listData, value, valueField, refList]);
priyanshubuddy commented 5 months ago

getting this error, again and again, need to be fixed, @gabrielroodriz you code converted the mi into warning but it's not worthy to edit in node modules for local use until it's merged in the library.

gabrielroodriz commented 5 months ago

Yes, I have a pull request open, waiting for approval for it: https://github.com/hoaphantn7604/react-native-element-dropdown/pull/279

kannan-rjp commented 5 months ago

Hi @gabrielroodriz , I faced this error. And apply your above file to my Dropdown index.tsx. It worked, but which selected it's not get select in my dropdown as a selected city its not appeared. What should i do?

daibergm commented 5 months ago

It bug was fixed on the version 2.10.4:

image