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

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

Open ds-shubhamsharma opened this issue 1 year ago • 5 comments

ds-shubhamsharma avatar May 24 '24 13:05 ds-shubhamsharma

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]);

gabrielroodriz avatar May 29 '24 20:05 gabrielroodriz

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.

priyanshubuddy avatar Jun 11 '24 08:06 priyanshubuddy

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

gabrielroodriz avatar Jun 12 '24 11:06 gabrielroodriz

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?

kannan-rjp avatar Jun 13 '24 05:06 kannan-rjp

It bug was fixed on the version 2.10.4:

image

daibergm avatar Jun 25 '24 01:06 daibergm