Skip to content

Commit

Permalink
Switch to userScrollEnabled for the carousel
Browse files Browse the repository at this point in the history
  • Loading branch information
tillh-stripe committed Aug 19, 2022
1 parent 9210ff3 commit d5b71c3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 36 deletions.

This file was deleted.

Expand Up @@ -8,15 +8,13 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.selection.selectable
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.ColorFilter
Expand Down Expand Up @@ -44,22 +42,14 @@ internal fun PaymentMethodsUI(
paymentMethods: List<SupportedPaymentMethod>,
selectedIndex: Int,
isEnabled: Boolean,
onItemSelectedListener: (SupportedPaymentMethod) -> Unit,
onItemSelectedListener: (SupportedPaymentMethod) -> Unit
) {
val scope = rememberCoroutineScope()
val state = rememberLazyListState()

LaunchedEffect(selectedIndex) {
state.scrollToItem(selectedIndex, 0)
}

LaunchedEffect(isEnabled) {
if (isEnabled) {
state.reenableScrolling(scope)
} else {
state.disableScrolling(scope)
}
}
PaymentsTheme {
BoxWithConstraints(
modifier = Modifier
Expand All @@ -70,10 +60,10 @@ internal fun PaymentMethodsUI(
paymentMethods.size
)

// TODO: userScrollEnabled will be available in compose version 1.2.0-alpha01+
LazyRow(
state = state,
contentPadding = PaddingValues(horizontal = PM_LIST_PADDING.dp),
userScrollEnabled = isEnabled,
modifier = Modifier.testTag(TEST_TAG_LIST)
) {
itemsIndexed(items = paymentMethods, itemContent = { index, item ->
Expand Down

0 comments on commit d5b71c3

Please sign in to comment.