I have a scrollable Column. At the bottom of the Column I want to disable scrolling and enable dragging in order to reveal an Image "behind" the Column.
This is what I've tried:
@Composable
fun DraggableScrollable() {
var offset by remember { mutableStateOf(0.dp) }
var dragging by remember { mutableStateOf(false) }
val interactionSource = remember { MutableInteractionSource() }
Box {
Column (
modifier = Modifier
.verticalScroll(
enabled = !dragging,
state = scrollState
)
.offset(y = offset.value)
.pointerInput(Unit) {
if (dragging) {
val interaction = DragInteraction.Start()
detectDragGestures (
onDragStart = { interactionSource.tryEmit(interaction) },
onDrag = { _, _ ->
// drag while offset != 0
// when offset is back to 0 enable scrolling again
},
onDragCancel = {
interactionSource.tryEmit(DragInteraction.Cancel(interaction))
},
onDragEnd = {
interactionSource.tryEmit(DragInteraction.Stop(interaction))
}
)
}
}
) {
repeat(100) {
Text(
text = "Item $it",
modifier = Modifier
.fillMaxWidth()
.padding(24.dp)
)
}
Button(onClick = { dragging = true }) { Text(text = "Reveal secret") }
}
Image(
painter = painterResource(id = R.drawable.foo),
contentDescription = "Secret image",
modifier = Modifier.fillMaxWidth().align(Alignment.BottomCenter)
)
}
}
However, that seems to only disable scrolling. Drag gestures do not register at all