Function

awaitVerticalTouchSlopOrCancellation

Waits for vertical drag motion to pass [touch slop][ViewConfiguration.

AwaitVerticalDragOrCancellationSample

@Composable
fun AwaitVerticalDragOrCancellationSample() {
    val offsetX = remember { mutableStateOf(0f) }
    val offsetY = remember { mutableStateOf(0f) }
    var height by remember { mutableStateOf(0f) }
    Box(Modifier.fillMaxSize().onSizeChanged { height = it.height.toFloat() }) {
        Box(
            Modifier.offset { IntOffset(offsetX.value.roundToInt(), offsetY.value.roundToInt()) }
                .fillMaxWidth()
                .height(50.dp)
                .background(Color.Blue)
                .pointerInput(Unit) {
                    awaitEachGesture {
                        val down = awaitFirstDown()
                        var change =
                            awaitVerticalTouchSlopOrCancellation(down.id) { change, over ->
                                val originalY = offsetY.value
                                val newValue =
                                    (originalY + over).coerceIn(0f, height - 50.dp.toPx())
                                change.consume()
                                offsetY.value = newValue
                            }
                        while (change != null && change.pressed) {
                            change = awaitVerticalDragOrCancellation(change.id)
                            if (change != null && change.pressed) {
                                val originalY = offsetY.value
                                val newValue =
                                    (originalY + change.positionChange().y).coerceIn(
                                        0f,
                                        height - 50.dp.toPx(),
                                    )
                                change.consume()
                                offsetY.value = newValue
                            }
                        }
                    }
                }
        )
    }
}