Any guides on how to build custom `Indication` ? :...
# compose
t
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
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
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
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
I don’t understand how we’ll draw two indicators at the same time 🤔 can you explain a little more?
l
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
ohhh we can apply indicator through modifier, that’s nice. that’s better than the second approach IMO.
l
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
It works!! 🚀 Thanks mate