reset scroll position when coming back from details page
how can i reset scroll position when coming back from details page of item ?
currently i am adding a class name to scrollable node , on backbutton click i am preserving scroll position in state and on coming back in component did update getting node by classname and setting scroll position stored previously , i don't know whether its okay to do like this or not ...
it will be nice if we have resetScrollPosition function
resetScrollPosition : function(newScrollTop) {
this.refs.scrollable.getDOMNode().scrollTop = newScrollTop
}
The idiomatic way of doing this seems to be adding an initialScrollPosition prop rather than the suggested function. In the meantime, you can use the handleScroll prop to get store the previous scroll position and get a reference to the scrolling DOM node to set later.
makes sense , initialScrollPosition :+1:
and get a reference to the scrolling DOM node to set later
how can i get this without adding a classname.. , i don't see any method exposed to get ref on fresh render ..
It's true it isn't possible to get it on the first render, but temporarily, for this specific use case where you only need to reset the position after the user has scrolled at least once, the DOM node is provided as the first argument to the function you pass to handleScroll.
hmm i can hold ref to DOM node on handleScroll ,when details component loaded listview (Infinite) is un mounted ,when coming back to list view(it will be rerendered again with previous state) , prev DOM node ref is not useful anymore! ..
Ah okay I don't think it'll be possible until the initialScrollPosition change is made.
classname trick working fine for me now , i'll update my code when initialScrollPosition landed .. , btw thanks alot for great component :)
Side note : If possible try to follow the prop names similar to https://facebook.github.io/react-native/docs/listview.html ;)
Edit : ah i forgot use case which actually needs resetScrollPosition(..) i have search box and listview when user scolled down in list view and then if he focus on search box i want to scroll to top . In this scenario i prefer exposing a mounted method resetScrollPosition over initialScrollPosition prop . may be we can have both! :)
Edit2: above use case can make it work via handleScroll but again resetScrollPosition(..) looks cleaner!
Any update on this? initialScrollPosition would be a very nice feature, especially for integrating something like an infinite calendar that can scroll both in the past and future
Unfortunately not yet, but an issue has come up in our work that may need this, and I'll see if I can get time scheduled to add it.
initialScrollPosition would be sweet and much needed.