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

theapache64

03/05/2022, 3:38 PM
Any guides on how to build custom
Indication
? 🤔 I am having trouble understanding how do I animate inside
IndicationInstance#ContentDrawScope.drawIndication()
.Problem is, its not a
@Composable
method, which means I can’t use animation API methods such as
animateXXXasState()
a

Adam Powell

03/05/2022, 3:49 PM
Indication.rememberUpdatedInstance(InteractionSource)
is a
@Composable
function. Any instance-specific composition to observe the
InteractionSource
and animate the returned
IndicationInstance
can be done there
t

theapache64

03/05/2022, 6:07 PM
ohh okay. is there any way i can have multiple indicators on top of one element. for eg, can i draw another indicator on top of ripple ?
l

Louis Pullen-Freilich [G]

03/05/2022, 7:25 PM
You could build your own
IndicationInstance
that draws some indication, and draws the ripple indication as well, although this sounds a bit suspicious and maybe not what you actually would want to do? On a side note, there is not much guidance currently - but it is something we are working on.
t

theapache64

03/05/2022, 7:53 PM
I don’t understand how we’ll draw two indicators at the same time 🤔 can you explain a little more?
l

Louis Pullen-Freilich [G]

03/05/2022, 8:13 PM
Well, I think you can either just do:
Modifier.indication(/* ripple */).indication(/** custom indication */)
So have two different indications, one for the ripple and one for your custom one. Or you could create an instance that wraps the ripple instance, and draws both:
Copy code
class CustomIndicationInstance(private val rippleInstance: IndicationInstance) : IndicationInstance {
    override fun ContentDrawScope.drawIndication() {
        // draw content, and ripple
        with (rippleInstance) { drawIndication() }

        // draw custom indication on top of ripple
        ...
    }
}
Depends what exactly you want to do
t

theapache64

03/05/2022, 8:15 PM
ohhh we can apply indicator through modifier, that’s nice. that’s better than the second approach IMO.
l

Louis Pullen-Freilich [G]

03/05/2022, 8:16 PM
Yeah, it depends what you need to do. If you wanted to clip the ripple / apply a scale effect to the ripple as well for example, then you would need to do the second approach - since it allows you to apply transformations to the ripple effect as well
👍 1
t

theapache64

03/05/2022, 8:47 PM
It works!! 🚀 Thanks mate
13 Views