diff --git a/components/CustomScrollView.tsx b/components/CustomScrollView.tsx index 23b5492..6608d08 100644 --- a/components/CustomScrollView.tsx +++ b/components/CustomScrollView.tsx @@ -89,20 +89,39 @@ const CustomScrollView: React.FC = ({ ); } + // 将数据按行分组 + const groupItemsByRow = (items: any[], columns: number) => { + const rows = []; + for (let i = 0; i < items.length; i += columns) { + rows.push(items.slice(i, i + columns)); + } + return rows; + }; + + const rows = groupItemsByRow(data, effectiveColumns); + // 动态样式 const dynamicStyles = StyleSheet.create({ listContent: { paddingBottom: responsiveConfig.spacing * 2, paddingHorizontal: responsiveConfig.spacing / 2, }, - gridContainer: { + rowContainer: { flexDirection: "row", - flexWrap: "wrap", - justifyContent: "space-evenly", + marginBottom: responsiveConfig.spacing, + }, + fullRowContainer: { + justifyContent: "space-between", + }, + partialRowContainer: { + justifyContent: "flex-start", }, itemContainer: { width: responsiveConfig.cardWidth, - marginBottom: responsiveConfig.spacing, + }, + itemWithMargin: { + width: responsiveConfig.cardWidth, + marginRight: responsiveConfig.spacing, }, }); @@ -115,13 +134,26 @@ const CustomScrollView: React.FC = ({ > {data.length > 0 ? ( <> - - {data.map((item, index) => ( - - {renderItem({ item, index })} + {rows.map((row, rowIndex) => { + const isFullRow = row.length === effectiveColumns; + const rowStyle = isFullRow ? dynamicStyles.fullRowContainer : dynamicStyles.partialRowContainer; + + return ( + + {row.map((item, itemIndex) => { + const actualIndex = rowIndex * effectiveColumns + itemIndex; + const isLastItemInPartialRow = !isFullRow && itemIndex === row.length - 1; + const itemStyle = isLastItemInPartialRow ? dynamicStyles.itemContainer : dynamicStyles.itemWithMargin; + + return ( + + {renderItem({ item, index: actualIndex })} + + ); + })} - ))} - + ); + })} {renderFooter()} ) : (