Код: Выделить всё
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun CanvasAction() {
var centerOffset by remember {
mutableStateOf(Offset.Zero)
}
var points by remember {
mutableStateOf(listOf())
}
Canvas(
modifier = Modifier
.fillMaxSize()
.pointerInput(key1 = Unit) {
detectDragGestures(
onDragStart = { offset ->
points = points + Point(offset = offset, isStartedPosition = true)
},
onDrag = { change, offset ->
change.historical.forEach {
centerOffset = it.position
}
points = points + change.historical.map {
Point(offset = it.position, isStartedPosition = false)
}
}
)
}
) {
drawCircle(
color = Color.Blue,
radius = 7.dp.toPx(),
center = centerOffset
)
val path = Path()
points.forEach { point ->
if (point.isStartedPosition) {
path.moveTo(point.offset.x, point.offset.y)
} else {
path.lineTo(point.offset.x, point.offset.y)
}
}
drawPath(
path = path,
color = Color.Blue,
style = Stroke(width = 2.dp.toPx())
)
}
}

Подробнее здесь: https://stackoverflow.com/questions/783 ... ck-compose