Does Compose UI get translated to Android Views un...
# compose
m
Does Compose UI get translated to Android Views under the hood to create native UIs and interact with the Android framework?
j
Yes, but not a separate AndroidView for each widget (that would be too slow). You get an AndroidView at the root, and occasionally in some other extenuating circumstances.
o
@jim so like one big canvas right?
j
Yeah, "one big canvas" a sufficiently true approximation.
r
To be more specific: it gets (sometimes) translated to Views, as in the base View class
❤️ 1
Not things like android.widget.Button for instance
m
So, for example, a box gets translated to a native FrameLayout? a LazyColumn to a native RecyclerView? and so on? Or has it nothing to do with framework Views?
j
No, individual widgets are not converted to Views. Only one View at the root to bootstrap the framework.
m
Maybe, Compose UI and Android View system are similiar mostly in the fact that they have some measure pass and some layout (I mean draw) pass, but they are co-independent and self-sufficient; They don't usually use each other to achieve a piece of UI. Am I right?
Also, the fact that they are tree-based!
j
All UI frameworks are ultimately tree based and have some sort of measure pass and some sort of draw pass.
Compose is highly interoperable with Views (you can use Android Views in your Compose tree and vice versa). We need to create Views at the root and in a few other circumstances, and they share a drawing layer. But those are mostly implementation details related to interoperability, for all intents and purposes, you can consider Compose to be an entirely new UI framework.
❤️ 1
👍 1
m
The Compose documentation is already nice, but I think it would be great to add some section (or content to some existing section), on how Compose works under the hood, a little bit of what Compose compiler does and how it interacts with Kotlin compiler and compiler extension, scratching a bit on how UI trees are constructed. In case it is not already hidden somewhere in the docs, I guess that would serve to satisfy some curiosity from people interested in the other side of things. Not sure if that would be much developer-friendly though.
j
There is an entire book on the topic: https://leanpub.com/composeinternals (I am not affiliated with the author and haven't read the book yet so I can't endorse it, but minimum price is free and it might be a good place to start)
❤️ 1
m
That's nice. Thank you @jim
The funny thing about my Compose journey is that when I was first introduced to compose in DevSummit 2019, I took the tutorial and said to myself "It's so easy." I got this! And now, after two years, I'm still learning Compose 😂 Nevertheless the Compose team did a great job delivering Compose to developers gradually from early alpha versions to stable. Developers kind of grew with the framework!