Skip to content

Commit

Permalink
Tabs - Remember current tab to avoid reseting it during recomposition
Browse files Browse the repository at this point in the history
  • Loading branch information
Tweener committed Jul 30, 2024
1 parent ca121eb commit 264e419
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand Down Expand Up @@ -65,7 +65,7 @@ fun PrimaryTabs(
showDivider: Boolean = false,
onTabChanged: (@Composable (String) -> Unit)? = null,
) {
var selectedTabIndex by remember { mutableIntStateOf(0) }
var selectedTabIndex by rememberSaveable { mutableIntStateOf(0) }

Column(modifier = modifier.fillMaxWidth()) {
PrimaryTabRow(
Expand Down Expand Up @@ -113,7 +113,7 @@ fun SecondaryTabs(
showDivider: Boolean = false,
onTabChanged: (@Composable (String) -> Unit)? = null,
) {
var selectedTabIndex by remember { mutableIntStateOf(0) }
var selectedTabIndex by rememberSaveable { mutableIntStateOf(0) }

Column(modifier = modifier.fillMaxWidth()) {
SecondaryTabRow(
Expand Down

0 comments on commit 264e419

Please sign in to comment.