diff --git a/app/src/main/java/com/example/research/ui/article/ArticleScreen.kt b/app/src/main/java/com/example/research/ui/article/ArticleScreen.kt index a7bbf25..14c4f23 100644 --- a/app/src/main/java/com/example/research/ui/article/ArticleScreen.kt +++ b/app/src/main/java/com/example/research/ui/article/ArticleScreen.kt @@ -123,59 +123,63 @@ fun ArticleContent( val isHeavyArticle = articleState.dslContent.size > HEAVY_ARTICLE_BLOCK_COUNT - LazyColumn( - state = listState, - contentPadding = PaddingValues(top = Spacing.listItemVertical), - modifier = modifier - .fillMaxSize() - .onSizeChanged { viewportSize = it } - .windowInsetsPadding(AppWindowInsets.horizontalSafeDrawing) - .padding(end = 16.dp) - .testTag("article_content") - .semantics { - testTagsAsResourceId = true - } - ) { - itemsIndexed( - items = articleState.dslContent, - key = { index, _ -> - // Use stable key combining article save key and index - "$articleSaveKey:$index" - }, - contentType = { _, _ -> "article_block" } - ) { index, block -> - val followedByContinuation = - articleState.dslContent.getOrNull(index + 1)?.continuesPrevious == true - val textContent = @Composable { - Box( - modifier = Modifier - .padding( - start = Spacing.contentStart + indentStep * block.indent + val articleList: @Composable (Modifier) -> Unit = { listModifier -> + LazyColumn( + state = listState, + contentPadding = PaddingValues(top = Spacing.listItemVertical), + modifier = listModifier + .testTag("article_content") + .semantics { + testTagsAsResourceId = true + } + ) { + itemsIndexed( + items = articleState.dslContent, + key = { index, _ -> + // Use stable key combining article save key and index + "$articleSaveKey:$index" + }, + contentType = { _, _ -> "article_block" } + ) { index, block -> + val followedByContinuation = + articleState.dslContent.getOrNull(index + 1)?.continuesPrevious == true + val textContent = @Composable { + Box( + modifier = Modifier + .padding( + start = Spacing.contentStart + indentStep * block.indent + ) + .padding(bottom = if (followedByContinuation) 0.dp else 8.dp) + ) { + ArticleLinkText( + block = block, + linksEnabled = true, + preferDirectHitTesting = isHeavyArticle, + style = baseTextStyle, + onRefClick = refClickHandler, + onTextLayout = {}, + modifier = Modifier + .testTag("article_block_$index") + .semantics { + testTagsAsResourceId = true + } ) - .padding(bottom = if (followedByContinuation) 0.dp else 8.dp) - ) { - ArticleLinkText( - block = block, - linksEnabled = true, - preferDirectHitTesting = isHeavyArticle, - style = baseTextStyle, - onRefClick = refClickHandler, - onTextLayout = {}, - modifier = Modifier - .testTag("article_block_$index") - .semantics { - testTagsAsResourceId = true - } - ) + } } - } - if (isHeavyArticle) { textContent() - } else { - SelectionContainer { textContent() } } } } + val articleListModifier = modifier + .fillMaxSize() + .onSizeChanged { viewportSize = it } + .windowInsetsPadding(AppWindowInsets.horizontalSafeDrawing) + .padding(end = 16.dp) + if (isHeavyArticle) { + articleList(articleListModifier) + } else { + SelectionContainer { articleList(articleListModifier) } + } } is ArticleState.Error -> { Column(