Hi, Is compose android build on the top of view system in android (xml)? I asked chat gpt but told ...
a
Hi, Is compose android build on the top of view system in android (xml)? I asked chat gpt but told me that
The Compose DSL allows you to define your UI elements and their properties using Kotlin functions, which are then compiled into a native Android view hierarchy at runtime.
So while Compose does not use XML-based layouts, it does use the underlying Android platform to handle the rendering and layout of the UI. In fact, Compose uses a custom implementation of the Android View system under the hood, but provides a much simpler and more intuitive way to work with it.
So is this correct?
🚫 1
v
No, it's not correct.
Composable functions are not "compiled into a native Android view hierarchy at runtime".
a
Thanks for your reply πŸ™ Any resources for this explanation?
p
Nope, Compose in fact is a tree snapshot reactive system. Compose-ui perhaps have some similarity with the view system because both sit on top of the Canvas API but the algorithms that relate the "view" nodes are way different. Resources: the source code
v
This book is probably the best non-official overview on how Compose works as a whole: https://jorgecastillo.dev/book/ For official documentation, you can check out the Android docs and source code: https://developer.android.com/jetpack/compose/documentation
In a nutshell and with some simplification, compose exists inside a single Android View. There are no extra views created for any composable layouts you create inside.
(You can, however, embed other Android Views inside the composition with
AndroidView
if you need to mix compose and Views)
a
Thanks for your great explanation πŸ™πŸ™
m
I'm waiting for that book for a long time now... really want to read it but it's not finished and I don't want to start reading an unfinished book.
p
Keep in mind Jorge's book is good for the theoretical side. It doesn't have code examples or things like that. It is basically to learn more about the theory behind it
m
Yes I'm aware, that's what's interesting to me!
z
The responses in this thread are mostly right, although there is one weird little caveat: on Android versions that don’t support RenderNodes, Compose creates a separate View for each graphics layer. But those are an implementation detail and those views are only used for graphics separation, not touch input, a11y info, layout, or anything else.
f
til
p
TIL2
153 Views