Skip to content

Commit

Permalink
MOB-277: Tab group scrolling improvement (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang authored Mar 7, 2024
1 parent 2ca9cca commit fa9e3b2
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.positionInParent
import androidx.compose.ui.text.font.FontVariation.weight
import androidx.compose.ui.unit.dp
import exchange.dydx.platformui.designSystem.theme.ThemeShapes
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch

@Composable
Expand All @@ -32,6 +34,8 @@ fun PlatformTabGroup(
val scrollState = rememberScrollState()
val scope = rememberCoroutineScope()

val selectionChangeInProgress = remember { MutableStateFlow(false) }

Row(
modifier = modifier
.horizontalScroll(scrollState)
Expand All @@ -52,7 +56,8 @@ fun PlatformTabGroup(
},
)
.onGloballyPositioned { coordinates ->
if (scrollingEnabled) {
if (scrollingEnabled && selectionChangeInProgress.value) {
selectionChangeInProgress.value = false
val size = coordinates.size
val position = coordinates.positionInParent()
val scrollPosition = scrollState.value
Expand Down Expand Up @@ -91,7 +96,12 @@ fun PlatformTabGroup(
item(
modifier = Modifier
.clickable {
onSelectionChanged(index)
if (index != currentSelection) {
onSelectionChanged(index)
if (scrollingEnabled) {
selectionChangeInProgress.value = true
}
}
},
)
}
Expand Down

0 comments on commit fa9e3b2

Please sign in to comment.