//导入插件
import React, { useState } from 'react';
// 渲染每一项的函数
const renderItem = ({ item }: { item: { id: string; teamOne: string; teamTwo: string; score: number; type: number } }) => (
<TouchableOpacity
style={styles.cellStyle}
// onPress={() => navigation.navigate('GameDetailPageScreen', { item })}
// onPress={() => Alert.alert('点击了比赛', `球队: ${item.team}, 分数: ${item.score}`)}
>
<View style={styles.floatViewStyle}>
<Image
source={require('../image/homeSports/homeRecommend.png')}
style={{ width: 61, height: 21, backgroundColor: 'transparent' }}
/>
</View>
<View style={styles.cellContentStyle}>
<Image
source={require('../image/homeSports/kuaichuang.png')}
style={{ width: 50, height: 50, marginBottom: 5, backgroundColor: 'transparent' }}
/>
<Text style={styles.teamTextStyle}>{item.teamOne}</Text>
</View>
{/* 中间的item */}
<View style={styles.cellContentStyle}>
{renderMiddleContent(item.type, item)}
</View>
<View style={styles.cellContentStyle}>
<Image
source={require('../image/homeSports/teamDefault.png')}
style={{ width: 50, height: 50, marginBottom: 5, backgroundColor: 'transparent' }}
/>
<Text style={styles.teamTextStyle}>{item.teamTwo}</Text>
</View>
</TouchableOpacity>
);
const HomeContent = () => {
return (
<View style={{ flex: 1, backgroundColor: 'white' }}>
<SectionList
sections={sections}
keyExtractor={(item, index) => index.toString()}
renderItem={({ item }) => renderItem({ item })} // ✅ 正确传递参数
renderSectionHeader={({ section: { title } }) => (
<View style={{ backgroundColor: 'black', padding: 10 }}>
<Text style={{ color: 'white', fontSize: 14 }}>{title}</Text>
</View>
)}
style={{ backgroundColor: "black", paddingBottom: 10 }}
/>
</View>
);
};
// css
const styles = StyleSheet.create({
cellStyle: {
height: 124,
width: '100%',
flexDirection: 'row',
backgroundColor: 'gray',
justifyContent: 'center',
alignItems: 'center',
marginTop: 10
},
});
//导出
export default HomeContent;
在页面中写的item
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 前言 Google Play应用市场对于应用的targetSdkVersion有了更为严格的要求。从 2018 年...