react-native - 如何在 RN 中将反向 FlatList 的加载指示器保持在顶部
问题描述
当 FlatList 倒置时,加载指示器会在底部,如何保持在顶部?
解决方案
我最终通过将 FlatList 包装在 ScrollView 中来解决问题,并将 refreshControl 留给 ScrollView。
const { fetchingMore, onFetchMore } = this.props;
return <ScrollView
contentContainerStyle={{
flexDirection: 'row',
alignSelf: 'flex-end',
flexGrow: 1
}}
refreshControl={<RefreshControl refreshing={fetchingMore} onRefresh={onFetchMore} />}
>
<FlatList
inverted
style={styles.list}
data={messages}
keyExtractor={this.extractItemKey}
renderItem={this.renderItem}
/>
</ScrollView>
请注意,flexGrow: 1
在scrollView中有样式很重要,否则FlatList在未满时会在scrollview的顶部流动。
推荐阅读
- c# - 使用 Itextsharp 为 PDF 添加时间戳
- python - 尝试在 Python 中读取 Matlab 文件时出现 SyntaxError(unicode 错误)
- remote-desktop - 如何在VB.net中连接到没有用户名和密码的远程桌面
- python - 向字典中的字典添加值
- android - 如果从 Android ReactActivity 调用组件,React Native 不会更新渲染 UI
- django - 为什么这个 OneToOneField 反向关系不持久化到数据库?
- arrays - 如何在处理中随机化特定颜色
- javascript - 在 reactjs 状态下通过数组表示法更新嵌套对象值
- html - 当我的输入被禁用时,如何从日期输入字段中删除 dd-mm-yyy
- laravel - 如何在 Vue JS 中显示图像