Thread
#compose
    Rolbin

    Rolbin

    1 year ago
    I have just started with compose and was going through the docs. In almost all the code snippets of the composable functions, with function passed as an argument, are not inlined (even for a 2-3 line function) Is there any specific reason for that?
    Filip Wiesner

    Filip Wiesner

    1 year ago
    My guess is that it is because the
    @Composable
    annotation marks a function that is changed by the compiler plugin. On the other hand
    inline
    functions are removed by the compiler (and substituted with the corresponding implementation in the call site). Plus the functions are used for identity and are re-called every recomposition so you need reference to it (which you wouldn't have if you remove it during compilation) Disclaimer: That's just my naive reasoning 🙂 I don't know enough about the compose compiler plugin to answer that
    If I understood your question correctly... was not surer for a sec 😅 You are asking why composable functions are not
    inline
    as
    @Composable inline fun Button(onClick: () -> Unit) { ... }
    Rolbin

    Rolbin

    1 year ago
    @Filip Wiesner Sorry if I wasn't clear with my question, anyway you got it right. Your reasoning seems to be valid, I will read more about that. Another question: If my understanding is correct, when we implement state hoisting, the composable function which manages the state won't be recomposed, right? What's your thought about inlining that?
    fal

    fal

    1 year ago
    @Rolbin Not who you asked, but the composable that manages state will be recomposed yes, assuming for example that you use collectAsState, I tested the other day and asked about it here