Skip to content

Commit

Permalink
fix the always scrolling of the pager when the item changes bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurKun21 committed Dec 30, 2023
1 parent 2bfc379 commit c57f9da
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/src/main/java/io/github/fate_grand_automata/ui/Tabbed.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import androidx.compose.material3.Tab
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch

@Composable
Expand All @@ -24,8 +26,10 @@ fun <T> Tabbed(
val pagerState = rememberPagerState(pageCount = {items.size})
val scope = rememberCoroutineScope()

LaunchedEffect(items) {
pagerState.scrollToPage(0)
LaunchedEffect(items.size) {
snapshotFlow { items.size }.collectLatest {
pagerState.scrollToPage(0)
}
}

Column(
Expand Down

0 comments on commit c57f9da

Please sign in to comment.