From 28f49ba8b547991f7312f07424f3892a17bfd263 Mon Sep 17 00:00:00 2001 From: Elie Gambache Date: Sat, 14 Nov 2026 23:19:39 +0200 Subject: [PATCH] fix(bookcontent): wait for the list layout before bringing the selected line into view The bring-into-view effect read listState.layoutInfo as soon as the pages had loaded, a frame before the list laid them out. On that stale layout (the loading item alone) the first TOC line looked off screen, so the list jumped to it and the book's title above it was hidden on open. Wait for a layout that holds the line's index first. --- .../ui/panels/bookcontent/views/BookContentView.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/SeforimApp/src/jvmMain/kotlin/io/github/kdroidfilter/seforimapp/features/bookcontent/ui/panels/bookcontent/views/BookContentView.kt b/SeforimApp/src/jvmMain/kotlin/io/github/kdroidfilter/seforimapp/features/bookcontent/ui/panels/bookcontent/views/BookContentView.kt index a0a8fbe78..cc1d5176d 100644 --- a/SeforimApp/src/jvmMain/kotlin/io/github/kdroidfilter/seforimapp/features/bookcontent/ui/panels/bookcontent/views/BookContentView.kt +++ b/SeforimApp/src/jvmMain/kotlin/io/github/kdroidfilter/seforimapp/features/bookcontent/ui/panels/bookcontent/views/BookContentView.kt @@ -338,6 +338,13 @@ fun BookContentView( val snapshot = lazyPagingItems.itemSnapshotList val index = snapshot.indices.firstOrNull { snapshot[it]?.id == primarySelectedLineId } if (index != null) { + // The pages land a frame before the list lays them out: judged on that stale layout (the + // loading item alone), the line looks off screen and the list jumps past the lines above it, + // the book's title among them. Wait for a layout that holds the line's index. + withTimeoutOrNull(1500L.milliseconds) { + snapshotFlow { listState.layoutInfo } + .first { info -> info.totalItemsCount > index && info.visibleItemsInfo.isNotEmpty() } + } val layoutInfo = listState.layoutInfo val visibleItems = layoutInfo.visibleItemsInfo val viewportEnd = layoutInfo.viewportEndOffset