1

我正在尝试通过点击按钮实现滚动到顶部功能以在滑动列表视图的顶部位置滚动并尝试从 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 })
}

操作系统:iOS 12.1

反应原生版本:v0.59.8

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

4

1 回答 1

3

列表视图的参考:listViewRef ={ ref => this.sectionListRef = ref }

和 scrolltop 功能应该是这样的:

scrollToTop() {
   this.sectionListRef.scrollToLocation({
            animated: true,
            itemIndex: 0,
            sectionIndex: 0,
            viewOffset: 0,
        });
}
于 2019-11-05T06:01:11.640 回答