Compose-Extended-Gestures
Compose-Extended-Gestures copied to clipboard
Reduce Boilerplate in pointerMotionEvent
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 */}
}
I can add option to assign a State like LazyColumn does. That why you can get touch state via it. If you have any suggestion feel free to post it
Sure! I'll experiment with it soon and see what we can do.