I would like to apply a draw transform to a wrappe...
# compose
t
I would like to apply a draw transform to a wrapped
IndicationInstance
, but
ContentDrawScope
doesn't allow for that.
Copy code
class ClipPathIndication(
    val indication: Indication,
    val path: Path
) : Indication {
    @Composable
    override fun rememberUpdatedInstance(interactionSource: InteractionSource): IndicationInstance {
        val innerInstance = indication.rememberUpdatedInstance(interactionSource)
        return remember(interactionSource, this, innerInstance) {
            Instance(innerInstance, path)
        }
    }

    class Instance(
        val innerInstance: IndicationInstance,
        val path: Path
    ) : IndicationInstance {
        override fun ContentDrawScope.drawIndication() {
            drawContent()
            clipPath(path) {
                innerInstance.drawIndication() // Not allowed; we're in DrawScope now.
            }
        }
    }
}
n
I think you need to use a with block and the corresponding
this
reference like so:
Copy code
override fun ContentDrawScope.drawIndication() {
            drawContent()
            clipPath(path) {
                with (innerInstance) {
                    this@drawIndication.drawIndication()
                }
            }
        }
t
ah, let me try that
hmm, wouldn't that draw in the outer scope though?
n
ContentDrawScope
is a sub interface of
DrawScope
so the instance that you are seeing in the
clipPath
trailing lambda is the same instance. It's just that you need to get a
ContentDrawScope
receiver scope to issue the
drawIndication
call. Hence the need to distinguish between which
this
reference