Marco Pierucci
11/11/2022, 12:02 AMpointerInteropFilter
But not sure why, maybe someone has a few pointers. 🧵Marco Pierucci
11/11/2022, 12:02 AM@ExperimentalComposeUiApi
@Composable
fun DrawingCanvas(
paths: MutableList<Path>
) {
val currentPath = paths.last()
val movePath = remember { mutableStateOf<Offset?>(null) }
Canvas(
modifier = Modifier
.fillMaxSize()
.clipToBounds()
.pointerInteropFilter { event ->
when (event.action) {
MotionEvent.ACTION_DOWN -> {
currentPath.moveTo(event.x, event.y)
}
MotionEvent.ACTION_MOVE -> {
movePath.value = Offset(event.x, event.y)
}
else -> {
movePath.value = null
}
}
true
}
) {
movePath.value?.let { offset ->
currentPath.lineTo(offset.x, offset.y)
drawPath(
path = currentPath,
color = Color.Black,
style = Stroke(5f)
)
}
paths.forEach {
drawPath(
path = it,
color = Color.Black,
style = Stroke(5f)
)
}
}
}
Marco Pierucci
11/11/2022, 12:02 AMMarco Pierucci
11/11/2022, 1:06 AMCanvas(
modifier = Modifier
.fillMaxSize()
.clipToBounds()
.pointerInteropFilter(
requestDisallowInterceptTouchEvent = onDisallowIntercept
) { event ->
onDisallowIntercept(true)
when (event.action) {
MotionEvent.ACTION_DOWN -> {
currentPath.moveTo(event.x, event.y)
}
MotionEvent.ACTION_MOVE -> {
movePath.value = Offset(event.x, event.y)
}
else -> {
movePath.value = null
}
}
true
}
)