add additional height calculation for album group

This commit is contained in:
jeffvli
2026-07-10 01:45:39 -07:00
parent f957fb0a05
commit 67a2be1559
6 changed files with 191 additions and 52 deletions
@@ -414,6 +414,38 @@ export function getAlbumGroupRowCount(
return end - start + 1;
}
export function getAlbumGroupSpanHeight(
groupRowCount: number,
baseHeight: number,
albumGroupImageSize: number,
contentHeight = 0,
): number {
const rowSpanHeight = groupRowCount * baseHeight;
const imageSpanHeight =
albumGroupImageSize > 0 ? Math.max(albumGroupImageSize, rowSpanHeight) : rowSpanHeight;
return Math.max(imageSpanHeight, contentHeight);
}
export function getAlbumGroupStartRowIndex(
rowIndex: number,
getRowItem: ((index: number) => unknown) | undefined,
enableHeader: boolean | undefined,
): number {
const item = getRowItem?.(rowIndex) as null | undefined | { album?: string };
if (!item?.album) return rowIndex;
const firstDataRow = enableHeader ? 1 : 0;
let start = rowIndex;
while (start > firstDataRow) {
const prevItem = getRowItem?.(start - 1) as null | undefined | { album?: string };
if (!prevItem || prevItem.album !== item.album) break;
start--;
}
return start;
}
export function isAlbumGroupingActive(columns: { id: string; isEnabled?: boolean }[]): boolean {
return columns.some((col) => col.id === TableColumn.ALBUM_GROUP && col.isEnabled);
}
@@ -513,9 +545,21 @@ function getAlbumGroupClampHeight(props: ItemTableListInnerColumn): null | numbe
props.enableHeader,
props.data.length,
);
const groupStartRowIndex = getAlbumGroupStartRowIndex(
props.rowIndex,
props.getRowItem,
props.enableHeader,
);
const contentHeight = props.albumGroupContentHeights?.get(groupStartRowIndex) ?? 0;
const totalGroupHeight = getAlbumGroupSpanHeight(
groupRowCount,
baseHeight,
albumImageSize,
contentHeight,
);
// Only clamp when the row was actually grown to fit the image.
if (albumImageSize <= groupRowCount * baseHeight) return null;
// Only clamp when the row was actually grown to fit the image or wrapped text.
if (totalGroupHeight <= groupRowCount * baseHeight) return null;
return baseHeight;
}