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 0110ca73..cab24494 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 abf3af0d..bbf033a5 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 4d92b5c6..2731f5c3 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,24 +1,30 @@ 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 +import androidx.compose.material.icons.outlined.ChevronRight import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.text.TextStyle import com.sebastianneubauer.jsontree.JsonTree import com.sebastianneubauer.jsontree.TreeState import com.sebastianneubauer.jsontree.defaultDarkColors import com.sebastianneubauer.jsontree.search.SearchState import com.sebastianneubauer.jsontree.search.rememberSearchState +import io.github.openflocon.library.designsystem.FloconTheme @Composable fun FloconJsonTree( json: String, modifier: Modifier = Modifier, initialState: TreeState = TreeState.FIRST_ITEM_EXPANDED, + textStyle: TextStyle = FloconTheme.typography.bodyMedium, onError: (Throwable) -> Unit = {}, - searchState: SearchState = rememberSearchState() + searchState: SearchState = rememberSearchState(), + lazyListState: LazyListState = rememberLazyListState() ) { SelectionContainer(modifier = modifier) { JsonTree( @@ -27,9 +33,11 @@ fun FloconJsonTree( FloconCircularProgressIndicator() // TODO Better? }, initialState = initialState, - icon = Icons.Outlined.ChevronLeft, + icon = Icons.Outlined.ChevronRight, searchState = searchState, + lazyListState = lazyListState, colors = defaultDarkColors, + textStyle = textStyle, onError = onError, modifier = Modifier.fillMaxSize() ) diff --git a/docs/sharedpref.md b/docs/sharedpref.md index 1b31879d..03c4bae7 100644 --- a/docs/sharedpref.md +++ b/docs/sharedpref.md @@ -25,7 +25,8 @@ To support Jetpack DataStore, ensure you have the `flocon-datastore` dependency: ```kotlin // build.gradle.kts -implementation("io.github.openflocon:flocon-datastore:version") +debugImplementation("io.github.openflocon:flocon-datastores:version") +releaseImplementation("io.github.openflocon:flocon-datastores-no-op:version") ``` Then register your DataStore: