Проблема, с которой я столкнулся Я столкнулся с тем, что поведение прокрутки LazyColumn переопределяет модификатор .swipeable() в Box. Когда пользователь находится в верхней части LazyColumn, я хочу, чтобы жест смахивания вниз закрывал ящик. Однако список просто подпрыгивает, а не вызывает действие пролистывания.
Вот минимальный воспроизводимый пример моего текущего кода:
Код: Выделить всё
@OptIn(ExperimentalWearMaterialApi::class)
@Composable
fun SwipeableHome() {
val appDrawSize = 1000.dp
val swipeableState = rememberSwipeableState(1)
val sizePx = with(LocalDensity.current) { appDrawSize.toPx() }
val anchors = mapOf(0f to 0, sizePx to 1) // Maps anchor points (in px) to states
val appsListScrollState = rememberLazyListState()
Box(
modifier = Modifier
.fillMaxSize()
.swipeable(
state = swipeableState,
anchors = anchors,
thresholds = { _, _ -> FractionalThreshold(0.3f) },
orientation = Orientation.Vertical,
enabled = isAppDrawAtTop.value
)
) {
Text("Home")
AppsList()
}
}
@Composable
fun AppsList() {
Box(
modifier = Modifier
.fillMaxSize()
.offset { IntOffset(0, swipeableState.offset.value.roundToInt()) }
) {
LazyColumn(
state = appsListScrollState,
modifier = Modifier
.offset { IntOffset(0, swipeableState.offset.value.roundToInt()) }
.fillMaxHeight()
) {
items(sortedInstalledApps) { app ->
AppsListItem(app)
}
}
}
}
Есть ли лучший способ обработать это взаимодействие, чтобы смахивание вниз вверху списка плавно закрывало ящик?
Что я пробовал:
Вот пример моей попытки вложенной прокрутки, для закрытия которой требуется два смахивания:
Код: Выделить всё
val isAppDrawAtTop = remember {
derivedStateOf { appsListScrollState.firstVisibleItemIndex == 0 && appsListScrollState.firstVisibleItemScrollOffset == 0 }
}
LazyColumn(
state = appsListScrollState,
modifier = Modifier
.offset { IntOffset(0, swipeableState.offset.value.roundToInt()) }
.fillMaxSize()
.nestedScroll(remember {
object : androidx.compose.ui.input.nestedscroll.NestedScrollConnection {
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
return if (available.y > 0 && isAppDrawAtTop.value) {
shouldScroll.value = false
Offset.Zero
} else {
shouldScroll.value = true
super.onPreScroll(available, source)
}
}
}
}),
userScrollEnabled = shouldScroll.value
) {
items(sortedInstalledApps) { app ->
SwipeAppsListItem(app)
}
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... e-when-the