mirror of
https://github.com/zimplexing/OrionTV.git
synced 2026-05-18 06:38:57 +08:00
fix(layout): improve video card grid alignment
- Implement intelligent row-based layout system - Full rows (3 cards) use space-between for even distribution - Partial rows (<3 cards) use flex-start for left alignment - Replace flexWrap approach with row grouping for better control - Add dynamic margin handling for different row types This resolves both the uneven spacing in full rows and scattered alignment in partial rows.
This commit is contained in:
@@ -89,20 +89,39 @@ const CustomScrollView: React.FC<CustomScrollViewProps> = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 将数据按行分组
|
||||||
|
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({
|
const dynamicStyles = StyleSheet.create({
|
||||||
listContent: {
|
listContent: {
|
||||||
paddingBottom: responsiveConfig.spacing * 2,
|
paddingBottom: responsiveConfig.spacing * 2,
|
||||||
paddingHorizontal: responsiveConfig.spacing / 2,
|
paddingHorizontal: responsiveConfig.spacing / 2,
|
||||||
},
|
},
|
||||||
gridContainer: {
|
rowContainer: {
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
flexWrap: "wrap",
|
marginBottom: responsiveConfig.spacing,
|
||||||
justifyContent: "space-evenly",
|
},
|
||||||
|
fullRowContainer: {
|
||||||
|
justifyContent: "space-between",
|
||||||
|
},
|
||||||
|
partialRowContainer: {
|
||||||
|
justifyContent: "flex-start",
|
||||||
},
|
},
|
||||||
itemContainer: {
|
itemContainer: {
|
||||||
width: responsiveConfig.cardWidth,
|
width: responsiveConfig.cardWidth,
|
||||||
marginBottom: responsiveConfig.spacing,
|
},
|
||||||
|
itemWithMargin: {
|
||||||
|
width: responsiveConfig.cardWidth,
|
||||||
|
marginRight: responsiveConfig.spacing,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -115,13 +134,26 @@ const CustomScrollView: React.FC<CustomScrollViewProps> = ({
|
|||||||
>
|
>
|
||||||
{data.length > 0 ? (
|
{data.length > 0 ? (
|
||||||
<>
|
<>
|
||||||
<View style={dynamicStyles.gridContainer}>
|
{rows.map((row, rowIndex) => {
|
||||||
{data.map((item, index) => (
|
const isFullRow = row.length === effectiveColumns;
|
||||||
<View key={index} style={dynamicStyles.itemContainer}>
|
const rowStyle = isFullRow ? dynamicStyles.fullRowContainer : dynamicStyles.partialRowContainer;
|
||||||
{renderItem({ item, index })}
|
|
||||||
|
return (
|
||||||
|
<View key={rowIndex} style={[dynamicStyles.rowContainer, rowStyle]}>
|
||||||
|
{row.map((item, itemIndex) => {
|
||||||
|
const actualIndex = rowIndex * effectiveColumns + itemIndex;
|
||||||
|
const isLastItemInPartialRow = !isFullRow && itemIndex === row.length - 1;
|
||||||
|
const itemStyle = isLastItemInPartialRow ? dynamicStyles.itemContainer : dynamicStyles.itemWithMargin;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View key={actualIndex} style={isFullRow ? dynamicStyles.itemContainer : itemStyle}>
|
||||||
|
{renderItem({ item, index: actualIndex })}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</View>
|
</View>
|
||||||
))}
|
);
|
||||||
</View>
|
})}
|
||||||
{renderFooter()}
|
{renderFooter()}
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
Reference in New Issue
Block a user