【问题标题】:scrollToLocatoin is not a function : react-native-swipe-list-viewscrollToLocatoin 不是函数:react-native-swipe-list-view
【发布时间】:2020-03-01 10:35:59
【问题描述】:

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

React Native 版本:v0.59.8

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

【问题讨论】:

    标签: react-native react-native-flatlist react-native-sectionlist


    【解决方案1】:

    列表视图参考​​:listViewRef ={ ref =&gt; this.sectionListRef = ref }

    and 和 scrolltop 函数应该是这样的:

    scrollToTop() {
       this.sectionListRef.scrollToLocation({
                animated: true,
                itemIndex: 0,
                sectionIndex: 0,
                viewOffset: 0,
            });
    }
    

    【讨论】:

    • 我错误地获取了listView的引用。不错的见解!!!谢谢
    • 使用 react hooks 还能实现吗?
    • 是的,有可能
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-20
    • 2020-06-27
    • 2015-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多