React Native - Scroll Listview at particular position - Programatically -
in ios objective-c can make uitableview
scroll particular row index using scrolltorowatindexpath
method in react-native did not find such way scroll listview
@ particular row index.
following scenario,
- there
listview
such expandable rows while tapping expands , expandable row containstextinput
component. - while inputting text in
textinput
, keyboard shown , ideally @ momentlistview
should scrolled (once keyboard downlistview
should scrolled down previous position).
this can achieved native-ios stuck in react-native.
i tried following way did not achieve well
there method called scrollto(x:0,y:10,animated:true)
in listview
component (actually method of scrollview
) can scrolled up/down based on y coordinate of parent view.
i receive keyboard's & down events in code , based on can somehow manage scrollto
method (by calculating y coordinate) when keyboard gets (as mentioned in @alexey's answer) have no idea how calculate y coordinate when keyboard gets down? (at moment ideally, listview should scroll down previous position).
any or hint appreciated!
what row height * item index
? let's want scroll 20th element in listview. each row has height: 50
. calculate offset @ 20th element using formula mentioned above: 50 * 20 = 1000
. use scrollto(0, 1000)
, you'll scroll desired element.
to able scroll back, need store offset before apply scrollto
function:
var scrollproperties = this.refs.listview.scrollproperties; var scrolloffset = scrollproperties.contentlength - scrollproperties.visiblelength;
after hook on keyboard's event (keyboardwillhide
deviceeventemitter
), can scrollto
previous offset.
Comments
Post a Comment