Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Comment on lines +80 to +82
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The !listState.isScrollInProgress check might lead to confusing behavior. If the user is in the middle of a scroll (e.g., a fling) and clicks to go to the next/previous search result, the auto-scroll won't trigger. This could make the navigation feel unresponsive. The user's explicit action to navigate should likely take precedence. Consider removing this check to make the auto-scroll behavior more predictable and reliable.

Suggested change
if(resultIndex != null && !listState.isScrollInProgress) {
listState.animateScrollToItem(resultIndex)
}
if(resultIndex != null) {
listState.animateScrollToItem(resultIndex)
}

}

FloconSurface(
modifier = modifier,
) {
Expand Down Expand Up @@ -101,6 +110,7 @@ private fun NetworkBodyContent(
FloconJsonTree(
json = body.text,
searchState = searchState,
lazyListState = listState,
onError = { jsonError = true },
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -160,15 +170,15 @@ 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())
FloconSmallIconButton(
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),
)
}
Expand Down
2 changes: 1 addition & 1 deletion FloconDesktop/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand All @@ -29,6 +32,7 @@ fun FloconJsonTree(
initialState = initialState,
icon = Icons.Outlined.ChevronLeft,
searchState = searchState,
lazyListState = lazyListState,
colors = defaultDarkColors,
onError = onError,
modifier = Modifier.fillMaxSize()
Expand Down