loloof64
04/23/2021, 8:34 AMComposable
, but I don't know how to make this drawing reactive to click. More in the thread.loloof64
04/23/2021, 8:36 AMclickCallback
handler. But how to make the content of drawIntoCanvas
react to this callback ?Cicero
04/23/2021, 8:39 AMCicero
04/23/2021, 8:40 AMloloof64
04/23/2021, 8:41 AMCicero
04/23/2021, 8:42 AMCicero
04/23/2021, 8:42 AMloloof64
04/23/2021, 8:42 AMCicero
04/23/2021, 8:42 AMCicero
04/23/2021, 8:42 AMCicero
04/23/2021, 8:43 AMloloof64
04/23/2021, 8:44 AMCicero
04/23/2021, 8:45 AMCicero
04/23/2021, 8:46 AMCicero
04/23/2021, 8:46 AMCicero
04/23/2021, 8:48 AMCicero
04/23/2021, 8:48 AMloloof64
04/23/2021, 8:48 AMCicero
04/23/2021, 8:49 AMloloof64
04/23/2021, 8:51 AMCicero
04/23/2021, 8:52 AMloloof64
04/23/2021, 8:54 AMDrawscope
. After, what I try to achieve may be impossible.Cicero
04/23/2021, 8:55 AMCicero
04/23/2021, 8:55 AMCicero
04/23/2021, 8:56 AMModifier.pointerInput(Unit) {
detectTapGestures(
onPress = { /* Called when the gesture starts */ },
onDoubleTap = { /* Called on Double Tap */ },
onLongPress = { /* Called on Long Press */ },
onTap = { /* Called on Tap */ }
)
}
To your canvas Modifierloloof64
04/23/2021, 8:58 AMDrawScope
reference, and a nativeCanvas
call. Again, I may be searching for an impossible use case.Cicero
04/23/2021, 8:59 AMCicero
04/23/2021, 8:59 AMCicero
04/23/2021, 9:00 AMCicero
04/23/2021, 9:00 AMCicero
04/23/2021, 9:00 AMloloof64
04/23/2021, 9:01 AMCicero
04/23/2021, 9:01 AMCicero
04/23/2021, 9:02 AMloloof64
04/23/2021, 9:03 AMCicero
04/23/2021, 9:04 AMCicero
04/23/2021, 9:04 AMCicero
04/23/2021, 9:04 AMCicero
04/23/2021, 9:04 AMCicero
04/23/2021, 9:05 AMZach Klippenstein (he/him) [MOD]
04/23/2021, 1:10 PMloloof64
04/23/2021, 5:34 PMCanvas(
mofifier = Modifier.pointerInput(Unit) {
detectDragGestures(
onDragStart = { handleDragStart(it) },
onDragCancel = { dndCancelCallback() },
onDrag = { change, dragAmount ->
change.consumeAllChanges()
dndMoveCallback(dragAmount.x, dragAmount.y)
},
onDragEnd = {
dndValidatingCallback()
})
detectTapGestures(
onTap = { offset ->
handleTap(offset)
}
))
fun handleTap(offset: Offset) {
//////////////////////////
println("Got tap at $offset")
//////////////////////////
}
loloof64
04/23/2021, 5:45 PMdetectTapGestures
or detectDragGestures
Zach Klippenstein (he/him) [MOD]
04/23/2021, 5:50 PMdetectDragGestures
, yeaCicero
04/23/2021, 6:43 PMCicero
04/23/2021, 7:22 PM@Composable
@Preview
fun DefaultPreview() {
Canvas(modifier = Modifier.fillMaxSize().pointerInput(Unit){
detectTapGestures(
onTap = {
println("FRAT")
}
)
}){
}
}
Cicero
04/23/2021, 7:22 PMloloof64
04/23/2021, 9:11 PMloloof64
04/23/2021, 9:17 PMCanvas(
modifier = modifier
.background(Color(214, 59, 96))
.pointerInput(Unit) {
if (dndState.pendingPromotion) {
/////////////////////////////
println("tap gestures")
////////////////////////////
detectTapGestures(
onTap = { offset ->
handleTap(offset)
}
)
}
else {
/////////////////////////
println("drag gestures")
//////////////////////////
detectDragGestures(
onDragStart = { handleDragStart(it) },
onDragCancel = { dndCancelCallback() },
onDrag = { change, dragAmount ->
change.consumeAllChanges()
dndMoveCallback(dragAmount.x, dragAmount.y)
},
onDragEnd = {
dndValidatingCallback()
})
}
},
) {
...
}
Zach Klippenstein (he/him) [MOD]
04/23/2021, 9:25 PMlaunch
each call into its own coroutine so they “run” concurrentlyloloof64
04/23/2021, 9:31 PMPointerInputScope
cannot receive launch
. Must I use a kind a wrapper ?
.pointerInput(Unit) {
launch {
detectTapGestures(
onTap = { offset ->
handleTap(offset)
}
)
}
launch {
detectDragGestures(
onDragStart = { handleDragStart(it) },
onDragCancel = { dndCancelCallback() },
onDrag = { change, dragAmount ->
change.consumeAllChanges()
dndMoveCallback(dragAmount.x, dragAmount.y)
},
onDragEnd = {
dndValidatingCallback()
})
}
My naive implementation doesn't work.loloof64
04/23/2021, 9:31 PMZach Klippenstein (he/him) [MOD]
04/23/2021, 9:37 PMcoroutineScope
loloof64
04/23/2021, 9:42 PMval coroutineScope = rememberCoroutineScope()
...
coroutineScope.launch {
...
}
Zach Klippenstein (he/him) [MOD]
04/23/2021, 9:45 PMpointerInput(Unit) {
coroutineScope {
launch {
detectTapGestures(…)
}
launch {
detectDragGestures(…)
}
}
}
Zach Klippenstein (he/him) [MOD]
04/23/2021, 9:45 PMloloof64
04/23/2021, 10:01 PMCicero
04/23/2021, 10:15 PMloloof64
04/24/2021, 8:11 AMloloof64
04/24/2021, 8:12 AMlaunch
and tap/drag gestures are not updated.loloof64
04/24/2021, 8:14 AMreversed: Boolean
, and the two handlers refer to this reversed
value. But though the recomposition happens and reversed
is changed, the behaviour of the two handlers stays the same. I mean it did not take into account the new reversed
value.loloof64
04/24/2021, 8:20 AMCicero
04/24/2021, 4:12 PMCicero
04/24/2021, 9:30 PM