lists: constant cards-per-row instead of measuring the grid

The adaptive grid resolves to exactly four cards on the TV's fixed full-
width pane — index % 4 needs no layout probing and cannot be skewed by
spanned items. Measuring existed only to re-derive the constant.
This commit is contained in:
Jeena 2026-10-13 23:24:12 +00:00
parent ec2b1f03b1
commit effc2bd9ae

View file

@ -91,20 +91,12 @@ fun VideoListScreen(
LaunchedEffect(source) { viewModel.loadChannelHeader(AppGraph.repository) } LaunchedEffect(source) { viewModel.loadChannelHeader(AppGraph.repository) }
} }
// Cards-per-row of the adaptive grid — LEFT from the first card of ANY row // Row starts of the 4-per-row grid: LEFT from a row's first card opens the
// must open the drawer (issue #7: "every time I'm all the way on the left"). // drawer (issue #7). rowCardWidth() sizes the adaptive columns to resolve
// Measure a CARD, not the first visible item: the page header spans the full // to exactly 4 on the full-width TV pane, so the row start is index % 4 —
// width, and reading its width made cards-per-row = 1 — every card near the // no layout measuring needed (measuring the first visible item instead was
// top then thought it was a row start and opened the drawer. // what made the full-span page header count as "one card per row").
val cellsPerRow by remember { val cardsPerRow = 4
androidx.compose.runtime.derivedStateOf {
val info = gridState.layoutInfo
val w = info.visibleItemsInfo
.firstOrNull { it.size.width < info.viewportSize.width }
?.size?.width ?: 0
if (w > 0) (info.viewportSize.width / w).coerceIn(1, 10) else 0
}
}
if (viewModel.loadingInitial && items.isEmpty()) { if (viewModel.loadingInitial && items.isEmpty()) {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
@ -170,7 +162,7 @@ fun VideoListScreen(
onClick = { lastOpenedIndex = index; onOpenVideo(video) }, onClick = { lastOpenedIndex = index; onOpenVideo(video) },
showPrivacy = source is ListSource.MyVideos, showPrivacy = source is ListSource.MyVideos,
compact = true, compact = true,
onLeftAtStart = if (index % cellsPerRow.coerceAtLeast(1) == 0) onOpenDrawer else null, onLeftAtStart = if (index % cardsPerRow == 0) onOpenDrawer else null,
onUpToTopBar = upToTopBar?.takeIf { index < 4 }, onUpToTopBar = upToTopBar?.takeIf { index < 4 },
modifier = Modifier modifier = Modifier
.focusRequester(fr), .focusRequester(fr),