Код: Выделить всё
data class RandomState(
val touchedPositions: Map = emptyMap(),
)
Код: Выделить всё
fun updateTouchedPositions(
touchedPositions: Map < Long, Pair < Float, Float >>
) {
println("Function from viewModel: $touchedPositions")
state = state.copy(
touchedPositions = touchedPositions)
}
Код: Выделить всё
.pointerInput(Unit) {
awaitEachGesture {
val positions = mutableMapOf < Long, Pair < Float, Float >> ()
do {
val event = awaitPointerEvent()
val canceled = event.changes.fastAny {
it.isConsumed
}
if (event.type == PointerEventType.Press) {
event.changes.forEach { pointer - >
val id = pointer.id.value
val x = pointer.position.x
val y = pointer.position.y
positions[id] = Pair(x, y)
}
println("Se van a guardar las posiciones: $positions")
viewModel.updateTouchedPositions(positions)
println("Posiciones de dedos en onPress: ${state.touchedPositions}")
}
if (event.type == PointerEventType.Release) {
println("Posiciones de dedos en onRelease: ${state.touchedPositions}")
}
} while (!canceled)
}
}
Код: Выделить всё
// ViewModel class
var state by mutableStateOf(RandomState())
private set
Подробнее здесь: https://stackoverflow.com/questions/783 ... in-compose
Мобильная версия