React Native - Scroll Listview at particular position - Programatically

Viewed 4515

In iOS with Objective-C we can make UITableView scroll to the particular row index by using scrollToRowAtIndexPath method but in React-Native I did NOT find such a way to scroll Listview at particular row index.

Following is the scenario,

  1. There is Listview with such expandable rows like while tapping it expands and the expandable row contains TextInput component.
  2. While inputting text in TextInput, the keyboard will be shown up and ideally at that moment Listview should be scrolled to up (once the keyboard get down Listview should be scrolled down to its previous position).

This can be easily achieved with Native-iOS but I am stuck in React-Native.

enter image description here


I TRIED FOLLOWING WAY BUT DID NOT ACHIEVE WELL

There is a method called scrollTo(x:0,y:10,animated:true) in Listview component (actually its method of Scrollview) by which it can be scrolled up/down based on the y coordinate of the parent view.

I successfully receive Keyboard's Up & Down events in my code and based on that I can somehow manage with scrollTo method (by calculating the y coordinate) when Keyboard gets up (as mentioned in @Alexey's answer) but I have NO idea about how to calculate y coordinate when Keyboard gets down? (At this moment ideally, the Listview should scroll down to its previous position).

Any help or hint would be appreciated!

1 Answers
Related