react-native - Flatlist 覆盖具有绝对位置的 a 元素
问题描述
我试图做出一个我想通过一个平面列表的视图,以便单击它时用户可以到达顶部。但是平面列表覆盖了该元素。
<View style={{backgroundColor:'#e6e6e6',flex:1,}>
<View style={{position:'absolute'}}>
<Text>Scroll To Reload</Text>
</View>
<FlatList refreshing={this.state.refresh} onRefresh={()=>this.refreshAllTweets()}
data={tweets}
keyExtractor={(item, index) => index.toString()}
renderItem={({item}) =>
<TweetItem onPress={()=>this.goToDetail(item.id)} onImagePress={()=>this.toggleModal(item.id)}
onCommentPress={()=>this.showComments(item.id)} tweet={item}/>}
/>
</View>
解决方案
视图中的每个子项都按顺序渲染,并最终堆叠在一起,直到所有子项都被渲染。由于您想要在顶部的视图首先被渲染,它将位于底部。更改您的代码,以便最后呈现您想要在顶部的视图。即将它移动到视图的底部。
<View style={{backgroundColor:'#e6e6e6',flex:1}}>
<FlatList
refreshing={this.state.refresh}
onRefresh={()=>this.refreshAllTweets()}
data={tweets}
keyExtractor={(item, index) => index.toString()}
renderItem={({item}) => <TweetItem onPress={()=>this.goToDetail(item.id)} onImagePress={()=>this.toggleModal(item.id)} onCommentPress={()=>this.showComments(item.id)} tweet={item}/>}
/>
<View style={{position:'absolute', top: 0}}>
<Text>Scroll To Reload</Text>
</View>
</View>
由于视图现在绝对定位,您可能希望给它一个实际位置。
FlatLast 有一个名为ListFooterComponent的 prop ,它接受一个 React 组件类、一个渲染函数或一个渲染元素。因此,您可以通过添加以下道具来更新您的 FlatList。
<FlatList
...
ListFooterComponent={
<View>
<Text>Scroll To Reload</Text>
</View>
}
/>
这会将视图作为页脚附加到 FlatList,因此当到达 FlatList 的底部时它将可见。
查看文档以获取有关FlatLists的更多信息。
推荐阅读
- unity3d - Unity 分析器中的 EarlyUpdate.Preloading
- android - Firebase 实时数据库数组查询问题
- angular - javascript 在一个模块文件中堆内存不足
- c# - 如何模拟自定义 ILoggerManager 进行 UnitTest
- c# - 我们可以使用 gmail 地址创建本地帐户用户吗?
- android - 如何在 DrawerLayout 内构建滑动 CardView?
- javascript - 如何在反应中按需动态导入第三方模块?
- c - 如何在 CLion 中链接 OpenSSL
- xml - 从一个xml文档生成多个html文件的问题
- bash - 奇点中不合逻辑的“不良替代”