https://kotlinlang.org logo
w

wasyl

10/24/2019, 3:30 PM
Another question 🙂 I see that
Layout
function calls
LayoutNode
with some paramerters and passes children. However I can’t seem to find
LayoutNode
function anywhere, and the class has no constructor, so where is it coming from? Does Compose plugin handle Node subclasses somehow and generate functions for them?
j

jim

10/24/2019, 4:35 PM
This API is going to change slightly, but basically, the Composer will accept some classes (like Android `View`s and anything extending
Emittable
) that it considers to be Composable. When these classes are used within Composable functions, we generate composable functions for them. The parameters of the generated composable functions can be called using named parameters, where the names coorespond to setters on the class. This allows you to use
TextView(text="Hello World")
, which will create a
TextView
, and set the text using
setText()
for any updates.
w

wasyl

10/24/2019, 4:37 PM
that it considers to be Composable
And for Android views it will be the leaf node, right? Anyway sounds nice, I guess I was mostly confused by IDE not complaining about the method I didn’t see in the source, but at the same time not completing when I wanted to use it myself 🙂
j

jim

10/24/2019, 4:46 PM
Yes, this is how we implement leaf nodes. If you were to implement a Compose UI library targeting a different tree type (eg. HTML), that's also how you would do it. There is nothing special about ComposeUI; it is all built on public API primitives.
👍 1
4 Views