Thread
#compose
    t

    tad

    1 year ago
    I would like to apply a draw transform to a wrapped
    IndicationInstance
    , but
    ContentDrawScope
    doesn't allow for that.
    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.
                }
            }
        }
    }
    Nader Jawad

    Nader Jawad

    1 year ago
    I think you need to use a with block and the corresponding
    this
    reference like so:
    override fun ContentDrawScope.drawIndication() {
                drawContent()
                clipPath(path) {
                    with (innerInstance) {
                        this@drawIndication.drawIndication()
                    }
                }
            }
    t

    tad

    1 year ago
    ah, let me try that
    hmm, wouldn't that draw in the outer scope though?
    Nader Jawad

    Nader Jawad

    1 year ago
    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