as answered here in order to get Y offset of a View in ScrollView hierarchy, we need to use onLayout and keep on adding Y offset of each parent of View (whose offset is needed relative to ScrollView) until we reach ScrollView. This process is tedious in large component hierarchies. I am trying to write a wrapper around react native's ScrollView which will expose a method called scrollIntoView which takes reference of the View you need to scroll to and scrolls to that view.
For this I am finding some way to start from given View's reference and start traversing ancestors of given View and keep adding their Y offset value which is provided by onLayout callback. but i am not sure how to do this.
Any help will be appreciated.
Note: onLayout gives Y offset relative to parent component hence we need to sum for each ancestor of view in order to calculate Y offset of view relative to ScrollView