- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 SectionList
组件时遇到问题,有时它不会呈现所有部分,而是只呈现第一部分。我已经进行了一些调试并且可能找到了修复方法,但我不知道为什么它可以解决问题。
我的页面总是会呈现第一部分,但有时不会呈现第二部分。通过一些测试,我发现如果我将所有项目放在一个部分下,它总是会毫无问题地呈现。这个问题似乎只有在另一个部分包含很多项目时才会发生。
代码看起来像这样:
const data = {
sections: [{
name: "First",
items: [{
name: "Item 1",
...
}]
},
{
name: "Second",
items: [{
name: "Item 20",
...
}]
}]
};
public render(): JSX.Element {
return (
<SafeAreaView>
<ScrollView refreshControl={this.getRefreshControl()}>
<SectionList
renderItem={({item}) => this.renderItem(item)}
renderSectionHeader={(section) => this.renderHeader(section)}
sections={this.getSections(data)}
keyExtractor={(_, index) => String(index)}
/>
</ScrollView>
</SafeAreaView>
);
}
getSections(data): SectionListData<any>[] {
const sections = data.sections.map(section => {
return {
title: section.name,
data: section.items
};
});
return sections;
}
我做了一些测试并从 View 层次结构中删除了 ScrollView
,它似乎已经解决了这个问题,但我无法重现它。我相信 ScrollView 有时会以某种方式导致 SectionList 出现问题,但我不知道为什么,也不知道如何证明这一点。有没有办法深入了解为什么会发生这个问题?或者以前有其他人遇到过这个问题吗?提前致谢!
最佳答案
SectionLists 有自己的滚动行为,由 VirtualizedList 提供.如果您将 SectionList 包裹在 ScrollView 中,滚动事件将被劫持,它会删除您想要的分段行为。
因为 SectionList 延迟加载,如果它无法访问滚动位置,那么它无法计算它是否超出 onEndReachedThreshold 并调用 onEndReached(以加载更多项目)。
SectionLists 和 FlatLists 被设计成可以无限滚动,所以你不应该将它们包裹在另一个 ScrollView 中。相反,如果您需要能够滚动浏览屏幕上的项目列表(无需延迟加载/分页),我会将它们全部静态加载到 ScrollView 中。
关于javascript - 为什么我的 SectionList 有时只呈现一个部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54246727/
所以我有一个包含数据的数组 var today = "2020-08-31" var array = [ { name: "Joshua", id: 1, date: "2020-08-3
我有下面的json结构 { "title": "Name(s)", "type": "Text", "data": [ { "source": "DB",
我是 react-native 的新手,尝试过使用 SectionList。到目前为止一切正常。但是,我似乎无法使用 facebook 文档中定义的 scrollToLocation 函数。有人试过使
您好,我有一个 sectionList,它传递了一组颜色 + 随机选择的背景 img,以呈现为每个行项目的背景。当我滑动访问该 View 时,颜色会闪烁几秒钟,因为随机选择仍在发生。每次我返回带有列表
我的 API 服务有以下数组结构 [ { id: 1001, orderNo: 'abc', customer: 'John', date: 15245262186
我有带部分的列表,但是这个 ListView 很慢。 我需要任何支架,但我不知道怎么做。 当我只有一种 View 时很简单,但在这里我遇到了问题。 我创建了 holder,但是当 ListView 显
我在使用 SectionList 组件时遇到问题,有时它不会呈现所有部分,而是只呈现第一部分。我已经进行了一些调试并且可能找到了修复方法,但我不知道为什么它可以解决问题。 我的页面总是会呈现第一部分,
我正在尝试显示一个包含多个列的部分列表。由于部分列表没有开箱即用的功能,我认为为每个部分项目呈现一个平面列表可能是个好主意。但我没有让它工作。 import React, { Component }
如果有这个简单的SectionList我的代码中的定义: const s = ( abc} renderSectionHeader={({ section }) => abc}
这个问题在这里已经有了答案: Basic FlatList code throws Warning - React Native (13 个回答) 4年前关闭。 我正在关注 SectionLists
我们可以添加像这个库一样的选项卡https://github.com/bogoslavskiy/react-native-tabs-section-list在部分列表中。我尝试了上面的库,它已经过时并
我对 React 和 React Native 还很陌生,但是在填充 SectionList 时遇到了问题,而且还找不到解决方案。 我有一个对象数组,每个对象都有它自己的数组。 SectionList
我正在使用 react-native 的 SectionList 并且无法隐藏数据集空白部分的部分标题。我只想显示部分标题和非空部分的行。 最佳答案 这就是我所做的: ( section
跟随 RN SectionList文档。如果我想像示例中那样构建同质部分列表: } renderSectionHeader={({section}) => } sections={[ //
我刚刚将我的 ListView 更改为 React Native 的新 SectionList,现在当我尝试使用 scrollTo 函数时应用程序崩溃,并指出它未定义。我尝试查找可能有帮助的新功能/替
我正在使用不同的节标题来呈现多个节。我在按我想要的方式显示它时遇到了一些麻烦。我希望我的标题位于顶部和下方,该部分的元素作为网格。 This is what I have right now 使用这段
使用 SectionList 时,虽然调用了 renderItem,但不会显示行。在列表上触发滚动时,行会立即出现。 我在 GitHub 上发现了一个问题讨论这个问题,但我没有找到任何解决方案来解决它
你知道如何在 sectionList 组件 React-native 中制作水平部分(特定)吗?我想让第二部分水平,我尝试使用 flex:1 和 flexDirection: 'row' 修改 ren
我有一个呈现多行的 SectionList。我正在尝试点击 renderItem 中的 View 。但我无法通过其 ID 访问该 View 。 I have used this to tap the
对于我正在处理的项目,我需要创建一个组件,用户可以在其中向处于状态的数组添加条目,还有一个 SectionList以显示这些条目。此外,我需要 SectionList 在输入后立即向下滚动到最新条目。
我是一名优秀的程序员,十分优秀!