I have just started with compose and was going thr...
# compose
r
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?
f
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
Copy code
@Composable inline fun Button(onClick: () -> Unit) { ... }
r
@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?
f
@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