https://kotlinlang.org logo
#compose
Title
# compose
s

Se7eN

03/04/2021, 3:51 PM
I have a
SnapshotStateList
of
Path
. How do I redraw when I edit one of my
Path
objects from the list? I'm implementing drawing with finger
Copy code
Canvas(
    modifier.pointerInput(Unit) {
        detectDragGestures(
            onDragStart = { position -> paths.add(Path().also { moveTo(...) }) },
            onDragEnd = { ... },
            onDragCancel = { ... },
            onDrag = { change, dragAmount ->
                change.consumePositionChange()
                paths.last().quadraticBezierTo(...)
            }
        )
    }
) {
    paths.value.forEach { path ->
        drawPath(path, ...)
    }
}
I'm currently faking a list item change like
paths[paths.lastIndex] = paths.last()
to make it work but it feels hacky
4 Views