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

Commit

Permalink
Scroll to top on change search term in exercises screen
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkitSuda committed Nov 25, 2022
1 parent a89a9e2 commit a4482f4
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Add
Expand All @@ -46,6 +47,7 @@ import com.ankitsuda.rebound.ui.theme.LocalThemeState
import me.onebone.toolbar.CollapsingToolbarScaffold
import com.ankitsuda.rebound.ui.theme.ReboundTheme
import com.google.accompanist.pager.ExperimentalPagerApi
import kotlinx.coroutines.delay
import me.onebone.toolbar.ScrollStrategy
import me.onebone.toolbar.rememberCollapsingToolbarScaffoldState

Expand Down Expand Up @@ -100,6 +102,14 @@ private fun ExercisesScreenContent(
onChangeSearchTerm: (String) -> Unit
) {
val collapsingState = rememberCollapsingToolbarScaffoldState()
val scrollState = rememberLazyListState()

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

BackHandler(isSearchMode) {
onToggleSearchMode()
Expand Down Expand Up @@ -154,6 +164,7 @@ private fun ExercisesScreenContent(
LazyColumn(
modifier = Modifier
.fillMaxSize(),
state = scrollState
) {
items(exercisesPaged, key = {
when (it) {
Expand Down

0 comments on commit a4482f4

Please sign in to comment.