From 809a234574af0c00b0a841ae118b639fe788666a Mon Sep 17 00:00:00 2001 From: Sebastian Neubauer Date: Sat, 31 Jan 2026 15:53:01 +0100 Subject: [PATCH] Add auto-scroll to JsonTree in detail view --- .../features/network/body/NetworkJsonScreen.kt | 14 ++++++++++++-- FloconDesktop/gradle/libs.versions.toml | 2 +- .../designsystem/components/FloconJsonTree.kt | 6 +++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/features/network/body/NetworkJsonScreen.kt b/FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/features/network/body/NetworkJsonScreen.kt index 0110ca73b..cab244947 100644 --- a/FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/features/network/body/NetworkJsonScreen.kt +++ b/FloconDesktop/composeApp/src/commonMain/kotlin/io/github/openflocon/flocondesktop/features/network/body/NetworkJsonScreen.kt @@ -14,6 +14,7 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.widthIn +import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.ArrowDownward @@ -68,11 +69,19 @@ private fun NetworkBodyContent( val scope = rememberCoroutineScope() val searchState = rememberSearchState() + val listState = rememberLazyListState() LaunchedEffect(query) { searchState.query = query } + val resultIndex = searchState.selectedResultListIndex + LaunchedEffect(resultIndex) { + if(resultIndex != null && !listState.isScrollInProgress) { + listState.animateScrollToItem(resultIndex) + } + } + FloconSurface( modifier = modifier, ) { @@ -101,6 +110,7 @@ private fun NetworkBodyContent( FloconJsonTree( json = body.text, searchState = searchState, + lazyListState = listState, onError = { jsonError = true }, modifier = Modifier .fillMaxWidth() @@ -160,7 +170,7 @@ private fun SearchBar( imageVector = Icons.Outlined.ArrowUpward, onClick = previousClicked, contentPadding = PaddingValues(all = 4.dp), - enabled = selectedResultIndex != null && selectedResultIndex > 0, + enabled = selectedResultIndex != null, modifier = Modifier.fillMaxHeight().aspectRatio(1f), ) VerticalDivider(modifier = Modifier.fillMaxHeight()) @@ -168,7 +178,7 @@ private fun SearchBar( imageVector = Icons.Outlined.ArrowDownward, onClick = nextClicked, contentPadding = PaddingValues(all = 4.dp), - enabled = selectedResultIndex != null && selectedResultIndex < totalResults - 1, + enabled = selectedResultIndex != null, modifier = Modifier.fillMaxHeight().aspectRatio(1f), ) } diff --git a/FloconDesktop/gradle/libs.versions.toml b/FloconDesktop/gradle/libs.versions.toml index abf3af0d8..bbf033a5d 100644 --- a/FloconDesktop/gradle/libs.versions.toml +++ b/FloconDesktop/gradle/libs.versions.toml @@ -31,7 +31,7 @@ aboutLibraries = "12.2.4" kotlinStdlib = "2.2.0" runner = "1.7.0" core = "1.7.0" -other-jsontree = "2.5.0" +other-jsontree = "2.6.0" uiToolingPreviewDesktop = "1.8.2" buildconfig = "5.6.8" paging = "3.3.2" diff --git a/FloconDesktop/library/designsystem/src/commonMain/kotlin/io/github/openflocon/library/designsystem/components/FloconJsonTree.kt b/FloconDesktop/library/designsystem/src/commonMain/kotlin/io/github/openflocon/library/designsystem/components/FloconJsonTree.kt index 4d92b5c66..d0c2618ca 100644 --- a/FloconDesktop/library/designsystem/src/commonMain/kotlin/io/github/openflocon/library/designsystem/components/FloconJsonTree.kt +++ b/FloconDesktop/library/designsystem/src/commonMain/kotlin/io/github/openflocon/library/designsystem/components/FloconJsonTree.kt @@ -1,6 +1,8 @@ package io.github.openflocon.library.designsystem.components import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.lazy.LazyListState +import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.ChevronLeft @@ -18,7 +20,8 @@ fun FloconJsonTree( modifier: Modifier = Modifier, initialState: TreeState = TreeState.FIRST_ITEM_EXPANDED, onError: (Throwable) -> Unit = {}, - searchState: SearchState = rememberSearchState() + searchState: SearchState = rememberSearchState(), + lazyListState: LazyListState = rememberLazyListState() ) { SelectionContainer(modifier = modifier) { JsonTree( @@ -29,6 +32,7 @@ fun FloconJsonTree( initialState = initialState, icon = Icons.Outlined.ChevronLeft, searchState = searchState, + lazyListState = lazyListState, colors = defaultDarkColors, onError = onError, modifier = Modifier.fillMaxSize()