scrollToLocatoin不是一个函数:react-native-swipe-list-view

我试图通过单击按钮来实现滚动到顶部功能,以在滑动列表视图的顶部位置滚动,并尝试从SectionList访问方法scrollToLocation,但是我无法使用SwipelistView的引用来访问它。所以我需要帮助来实现它。下面是渲染函数中的代码。

<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 }
    />

滚动到列表顶部的代码。

scrollToTop() {
   this.sectionListRef.scrollToLocation({ offset : 0,animated : true })
}

OS:iOS 12.1

反应本机版本:v0.59.8

native-swipe-list-view版本:v2.0.3

ygbyyy 回答:scrollToLocatoin不是一个函数:react-native-swipe-list-view

listview的引用:listViewRef ={ ref => this.sectionListRef = ref }

and和scrolltop函数应类似于:

scrollToTop() {
   this.sectionListRef.scrollToLocation({
            animated: true,itemIndex: 0,sectionIndex: 0,viewOffset: 0,});
}
本文链接:https://www.f2er.com/3162165.html

大家都在问