Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
Fix auto scroll to top in exercises screen
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkitSuda committed Nov 25, 2022
1 parent 1bfbfd5 commit de311f2
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.compose.material.icons.outlined.Add
import androidx.compose.material.icons.outlined.Search
import androidx.compose.runtime.*
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -104,11 +105,18 @@ private fun ExercisesScreenContent(
val collapsingState = rememberCollapsingToolbarScaffoldState()
val scrollState = rememberLazyListState()

var lastSearchTerm by rememberSaveable {
mutableStateOf(searchTerm)
}

LaunchedEffect(key1 = searchTerm) {
delay(100)
if (scrollState.firstVisibleItemIndex != 0) {
scrollState.animateScrollToItem(0)
if (lastSearchTerm != searchTerm) {
delay(100)
if (scrollState.firstVisibleItemIndex != 0) {
scrollState.animateScrollToItem(0)
}
}
lastSearchTerm = searchTerm
}

BackHandler(isSearchMode) {
Expand Down

0 comments on commit de311f2

Please sign in to comment.