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

Sheroz Nazhmudinov

04/26/2020, 1:31 PM
hey, is there any good reference for the compose api to draw the shapes for custom UI elements (and make them user intractable)? So I was using canvas fo that purpose, and wanted to clarify if that’s the right approach?
a

Adam Powell

04/26/2020, 4:51 PM
it's a goal of compose to make it easy to do it that way, so sure, please report back 🙂
you might want to poke around in the
ui-foundation
layers as a lot of interaction constructs live there to be used in building components like that
s

Sheroz Nazhmudinov

04/26/2020, 6:04 PM
sounds good, i wanted to give it a try - drawing custom ui components and make them user intractable🙂
👍 1
I have a use case at the moment: I have a custom view and I want to make certain “part” of it draggable. So i was thinking if that’s the right approach:
@Composable
fun Custom(modifier: Modifier = Modifier) {
Canvas(modifier = modifier.plus(
Modifier.draggable(dragDirection = DragDirection.Horizontal) {
// drag callback
}
)) {
drawRoundRect(...)
drawCircle(...)
}
}
So in my case i wanna make circle draggable.
a

Adam Powell

04/26/2020, 8:43 PM
first off, just do
modifier.draggable(...)
,
modifier.plus(Modifier.draggable(...))
is entirely redundant 🙂
👍 1
s

Sheroz Nazhmudinov

04/27/2020, 11:39 AM
so to make it a bit simpler i decide to do smth else: I wrapped the
Canvas
with
Clickable
, and wanted to change the state of circle based on click. However, the click isn’t triggered. The only way I managed to trigger the
onClick
was setting the specific
width
and
height
in
Clickable
via the `modifier`… i guess i’d expect the
Clickable
to have already the size of the content of the
Canvas
. I hope it makes sense what I’m trying to say…
a

Ash

04/27/2020, 8:42 PM
Can we make certain part of the canvas clickable?
For example a rectangle inside the canvas?
s

Sheroz Nazhmudinov

04/28/2020, 7:29 PM
i get a compile error when i try to make some parts of custom drawing clickable.
Functions which invoke @Composable functions must be marked with the @Composable annotation