Skip to content

fix(bookcontent): keep the book title visible on open - #776

Merged
kdroidFilter merged 1 commit into
masterfrom
fix/book-title-bring-into-view
Nov 15, 2026
Merged

kdroidFilter merged 1 commit into
masterfrom
fix/book-title-bring-into-view

Conversation

@kdroidFilter

Copy link
Copy Markdown
Owner

Problem

On open, a book sometimes showed its first TOC line at the top, with the book's title (above it) scrolled out of view.

The bring-into-view effect read listState.layoutInfo as soon as the pages had loaded, one frame before the LazyColumn laid them out. On that stale layout (the loading item alone, total=1), the selected line looked off screen, so the effect called scrollToItem(index) and jumped past the lines above it, the title among them.

Trace from a failing run:

bringIntoView line=2 index=1 first=0 visible=[0] total=1 fully=false -> scrollToItem(1)

Fix

Before judging visibility, wait (up to 1.5 s) for a layout that holds the line's index:

withTimeoutOrNull(1500L.milliseconds) {
    snapshotFlow { listState.layoutInfo }
        .first { info -> info.totalItemsCount > index && info.visibleItemsInfo.isNotEmpty() }
}

Verification

  • Reproduced the missing title in E2E runs (ZAYIT_E2E_SCENARIO, isolated user DB) with traces showing the stale layout.
  • With the fix, the title was present in 11/11 runs. The stale-layout path came up in 2 of them and no longer scrolled.
  • ktlintCheck and detekt pass.

…ed 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.
@kdroidFilter
kdroidFilter merged commit 1ca590f into master Nov 15, 2026
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant