javascript - FlatList scroll with the static component
问题描述
I have one static component and many for loop rendered components in a screen.
The all code below here.
import React from "react";
import { View, Text, FlatList } from "react-native";
...
class FlatListScrollWithStatic extends React.Component {
render() {
return (
<View style={{ flex: 1 }}>
<FriendsTop /> // the static component
<FlatList
style={{ flex: 1 }}
data={this.props.friendsCard}
renderItem={({ item }) => <FriendsCard {...item} />} // the for loop rendered components
keyExtractor={(item, index) => index.toString()}
/>
</View>
);
}
}
Now I want to migrate the FriendsTop into Flatlist, let it scroll with the rendered components, how should I change my code?
解决方案
Flatlist 有一个ListHeaderComponent
接受 JSX 元素的 prop。所以:
import React from "react";
import { View, Text, FlatList } from "react-native";
...
class FlatListScrollWithStatic extends React.Component {
render() {
return (
<View style={{ flex: 1 }}>
<FlatList
style={{ flex: 1 }}
data={this.props.friendsCard}
renderItem={({ item }) => <FriendsCard {...item} />} // the for loop rendered components
keyExtractor={(item, index) => index.toString()}
ListHeaderComponent={<FriendsTop />}
/>
</View>
);
}
}
推荐阅读
- c - 通过 HCI 建立 L2CAP 连接
- google-apps-script - 从谷歌应用脚本中的按钮传递参数
- sql - 从 SQL 中的多个表中选择数据的最有效方法是什么?
- java - 在 JUnit 中使用参数化类时出现 Varargs 错误
- excel - VBA中的调用函数
- html - 我怎样才能摆脱菜单和子菜单之间的差距
- r - 如何从R中的excel(在不同的工作表中)绘制具有多个X,Y(向量)的散点图
- c# - 按钮创建一个按钮,然后该按钮显示/隐藏表单
- azure-active-directory - 是否可以拥有一个使用具有不同配置的 Azure B2C 的 Web 应用程序
- ffmpeg - 将 ffmpeg d3dva 纹理资源复制到共享渲染纹理