'Check if a node is a descendant of a scrollview in React Native

I'm trying to patch a library. It has the following piece of code:

const { scrollView } = this.state;
await this.state.currentStep.wrapper.measureLayout(
  findNodeHandle(scrollView), (x, y, w, h) => {
    // do something
  });

This works fine on Android. However, on iOS, if currentStep.wrapper (a React Element) is not inside the scrollview, the app crashes with the following error:

Error

This error cannot be catched. I need to check if the node is a descendant of the scrollview before doing measureLayout() to prevent the crash. Is it possible?

I'm using (react 17.0.2), and (react-native 0.66.3).



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source