robnik
02/28/2021, 3:03 PMCanvas
. I use Modifier.draggable
, but the handler does not have access to the Canvas's width, to constrain the drag. How can I pass the Canvas's width to the drag handler? Example in thread...robnik
02/28/2021, 3:14 PMval offset = remember { mutableStateOf(0f) }
val dragState = rememberDraggableState { dx ->
offset.value = (offset.value + dx).coerceIn(0f, ???) // canvas width?
}
Canvas(Modifier.fillMaxWidth().height(40.dp)
.draggable(orientation = Orientation.Horizontal,
state = dragState)) {
// this.size.width is available here. How to pass to the drag handler?
drawThing(offset)
}
Se7eN
02/28/2021, 4:09 PMModifier.onSizeChanged
on the Canvas
to get it's size:
val size by remember { mutableStateOf(0.dp) }
val dragState = rememberDraggableState { dx ->
offset.value = (offset.value + dx).coerceIn(0f, size.width)
}
Canvas(modifier = Modifier
...
.onSizeChanged { size = it }
...
)
Adriano Celentano
02/28/2021, 4:18 PMpointerInput
like here
https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]s/src/main/java/androidx/compose/animation/demos/FlingGame.ktrobnik
02/28/2021, 4:23 PM