I just changed my ListView to React Native's new SectionList and now the app crashes when I attempt to use the scrollTo function, stating that it's undefined. I tried looking up new/alternative functions that may help, but none of them seem to be working.
What's the proper protocol for programmatically scrolling to a specific section with the new SectionList?
Links I've been consulting thus far: https://github.com/facebook/react-native/issues/13151 https://facebook.github.io/react-native/releases/0.43/docs/virtualizedlist.html#scrolltoend
My current attempt:
var params = {animated:true,offset:Platform.OS == "ios" ? 244 : 264}
_mainListView.scrollToOffset(params)
<SectionList
ref={(sectionList) => { this.sectionList = sectionList }} .../>
this.sectionList.scrollToLocation(
{
sectionIndex: sectionIndex,
itemIndex: itemIndex
}
);
This is what I used to get it working using a mix of this post and https://snack.expo.io/HJp9mEQkG
This is how I scroll to end
listRef.current?.scrollToLocation({
animated: true,
sectionIndex: sections.length - 1,
itemIndex: sections[sections.length - 1].data.length - 1,
})
This is how I scroll to top
listRef.current?.scrollToLocation({
animated: true,
sectionIndex: 0,
itemIndex: 0,
})
scrollToSection = (sectionIndex,itemIndex = 1 ) => {
this.refs.foo.scrollToLocation({
sectionIndex: sectionIndex,
itemIndex: itemIndex
});
}
sectionList:
<SectionList
ref = "foo",
//something
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With