I am trying to implement scroll to top function on tap of button to scroll on top position of swipe list view and trying to access method scrollToLocation from SectionList but I am not able to access it using the reference of SwipeListView. So I need help how to achieve it.Below is code from render function.
<SwipeListView
useSectionList={true}
sections={this.state.data}
keyExtractor={(item, section) => item.key }
renderItem={this.renderRow}
renderHiddenItem={this.renderHiddenItems}
renderSectionHeader={this.renderSectionHeader}
rightOpenValue={-75}
stopRightSwipe={-75}
previewRowKey={'0'}
closeOnRowPress={true}
previewOpenValue={-40}
onRowDidOpen={this.onRowDidOpen}
stickySectionHeadersEnabled={false}
bounces
disableRightSwipe={true}
enableEmptySections={false}
tension={20}
scrollsToTop={true}
onEndReachedThreshold={0.99}
onEndReached={() => {
this.setState({ isScrollToTopVisible: !this.state.isScrollToTopVisible })
}}
ref={(ref) => this.sectionListRef = ref }
/>
Code for scroll to top of list.
scrollToTop() {
this.sectionListRef.scrollToLocation({ offset : 0, animated : true })
}
OS: iOS 12.1
React Native Version: v0.59.8
React-native-swipe-list-view Version: v2.0.3
reference of listview : listViewRef ={ ref => this.sectionListRef = ref }
and and scrolltop function should be like :
scrollToTop() {
this.sectionListRef.scrollToLocation({
animated: true,
itemIndex: 0,
sectionIndex: 0,
viewOffset: 0,
});
}