Hi,folks! If I want to know how the Composable fun...
# compose
i
Hi,folks! If I want to know how the Composable function becomes the ui node and then the ui tree is formed, and how the modifier ultimately affects our Composable functions?Can I know by reading the source code of
Composer
or
LayoutNode
? Or what source code do I need to read to get these knowledges? I am very confused and I want to know the principle behind the implementation.
j
Probably you want to look at
UiApplier
UiApplier roughly sits between the
Composer
and
LayoutNode
, so you're in the right ballpark.
i
Thanks Jim @jim, I saw the source code of
UiApplier
and the sample of it. I general understading how
composable function
becomes
LayoutNode
.Maybe at the compile time the compose compiler call the
emit
function in each composable function?
In order to have a deeper understanding of the working principle behind compose, do I need to learn some knowledge of the compose compiler? Reading only the source code of
Composer, LayoutNode, and UiApplier
. I found it is difficult to connect them with composable function.
j
I think maybe you are assuming that composable functions are converted into some sort of widget-like data structure, and assuming that data structure is a LayoutNode?
I think maybe you are getting that assumption because you are holding on tightly to the mental model of Views?
i
Yes, I try to think in a way I can understand.
j
It is better to think of composable functions as function calls. We track the function calls in the slot table to ensure that the layout nodes are moved around properly (via the UiApplier) but the composable functions themselves are not "converted" into LayoutNodes. Layout nodes are typically emitted when a composable function invokes
Layout
from
Layout.kt
It may be worth setting a breakpoint in
LayoutNode
(and possibly
UiAdapter
too) so you can see where they are called, walk up the call stack, and see the values.
i
Thanks, I will have a try!!😀Haven't you slept so late?😂😂
😂 1