0

I want to detect drag gesture behavior for my ModalBottomSheetLayout. I want to catch the event when user swipes drags the sheet up trying to expand it.

ModalBottomSheetLayout(
    sheetState = sheetState,
    sheetContent = {
        content()
    },
    modifier  = modifier
        .pointerInput(Unit) {
            detectDragGestures { change, dragAmount ->
                change.consume()
                val (x, y) = dragAmount
                when {
                    y > 0 -> {
                        coroutineScope.launch {
                            sheetState.hide()
                        }
                    }

                    y < 0 -> {
                        coroutineScope.launch {
                            sizeRatio = if (sheetState.isVisible) 1f else 0.7f
                            sheetState.animateTo(ModalBottomSheetValue.Expanded)
                        }
                    }
                }
                offsetX += dragAmount.x
                offsetY += dragAmount.y
            }
        },
    content = {}
)

My problem is - the detectDragGestures detects X coordinate drags, but it doesn't react to Y coordinate drags. I guess that's b/c ModalBottomSheetLayout consumes those events already. Is there a way to make it work?

Rainmaker
  • 10,294
  • 9
  • 54
  • 89

0 Answers0