Counterpart of onTouchEvent, TouchDelegate, Transform gestures that notifies start, end, main pointer, pointers and option to consume PointerInputChange which defines whether other gestures should receive or not.
Every time I use the callback function, I need to assign the motionEvent enum type to the function. Is there a way to reduce this boilerplate code?
Currently
@Composable
fun Component() {
var motionEvent by remember { mutableStateOf(MotionEvent.Idle) }
Canvas(
modifier = Modifier
.clipToBounds()
.pointerMotionEvents(
onDown = { motionEvent = MotionEvent.Down; /* more code */},
onMove = { motionEvent = MotionEvent.Move; /* more code */},
/* etc */
)
) { /* Drawing the elements */}
}
Proposal
@Composable
fun Component() {
val motionEvent = rememberMotionEvent()
Canvas(
modifier = Modifier
.clipToBounds()
.pointerMotionEvents(motionEvent) {
onDown = {/* no need to manually set motionEvent */}
onMove = {/* no need to manually set motionEvent */}
/* etc */
}
) { /* Drawing the elements */}
}
Every time I use the callback function, I need to assign the
motionEvent
enum type to the function. Is there a way to reduce this boilerplate code?Currently
Proposal