react-native - 需要创建一个显示数组列表的设计
解决方案
最终输出:
没什么好解释的,只是一点点 CSS 样式。
还有一种,我不知道快照中使用的字体,所以我使用的是默认字体。
稍后根据您的 UI 更改它。
这是完整的代码:
export default function App() {
const [persons, setPersons] = useState(personData);
const renderInfoCard = (data) => {
return (
<View style={styles.container}>
<Text style={styles.heading}>Director/Partner Details</Text>
<FlatList
style={{
backgroundColor: '#F7F9FA',
flex: 1,
margin: 2,
borderRadius: 3,
}}
data={data}
renderItem={({ item }) => {
return (
<View style={{ flexDirection: 'row', flex: 1, padding: 5 }}>
<View style={{ flex: 1 }}>
<Text style={{ color: 'grey' }}>{item.post}</Text>
</View>
<View style={{ flex: 1 }}>
<Text style={{ fontWeight: '500' }}>{item.name}</Text>
</View>
</View>
);
}}
/>
</View>
);
};
return <SafeAreaView>{renderInfoCard(persons)}</SafeAreaView>;
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'start',
paddingTop: Constants.statusBarHeight,
backgroundColor: 'white',
padding: 8,
},
heading: {
fontSize: 15,
fontWeight: '500',
textAlign: 'start',
marginLeft: 15,
marginBottom: 5,
marginTop: 10,
},
});
const personData = [
{
id: 1,
post: 'Director 1',
name: 'John',
},
{
id: 2,
post: 'Director 2',
name: 'Bruce',
},
{
id: 3,
post: 'Director 3',
name: 'Clarke',
},
{
id: 4,
post: 'Director 4',
name: 'Peter',
},
{
id: 5,
post: 'Director 5',
name: 'Tony',
},
];
您可以在此处使用工作示例:Expo Snack
推荐阅读
- javascript - 如何根据对象的值获取 id 并设置到另一个对象中 - javascript
- python - 在 Python 中使用 Jacobi 迭代计算马尔可夫链的平衡概率
- python - 如何获得第 3 列的长度?Python
- ios - 在 PDFKit 中隐藏指示器滚动
- python - ea function my_within_tolerance(A, a, tol) 其中输出是 A 中索引的数组或列表,使得 |A − a| <托尔
- javascript - 状态不随 useContext 改变
- java - java md5在javaagent模式下很慢
- json - 数据框行到 JSON 给出不正确的结果
- python - 如何在python中从头开始使用TF-idf制作朴素贝叶斯多项式?
- ios - 排除的源文件名导致找不到 pod 头文件