Timo Drick

    Timo Drick

    1 year ago
    How can i call a @Composable function from reflection. I know that the compiler plugin will add two additional parameters to the function. The question is what should i provide in this first two parameters. One needs the Composer and the second an Int (I think it is the slot). Is it possible to do this via reflection?
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    i don’t think this is officially supported, but I remember Leland saying that the int parameter was designed so it would be reasonable to pass 0 to initially, or something like that. So then you just need the composer. There’s some code in the preview infra that you might look for calls to in the rest of the codebase: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]ewUtils.kt;l=166;drc=6867aa1d8441dd83fc3c06c2e135c4d11e5228f6
    Adam Powell

    Adam Powell

    1 year ago
    it's a bitfield that communicates parameter stability and comparison propagation
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    right, so passing zero every time should technically work, it just won’t get any of the optimizations, right?
    Adam Powell

    Adam Powell

    1 year ago
    yeah, iirc
    getting some docs about the abi of this into an official location is on the todo list
    Timo Drick

    Timo Drick

    1 year ago
    @Zach Klippenstein (he/him) [MOD] Thank you very much for this link. Exactly what i need. I will try it later.