wasyl

    wasyl

    2 years ago
    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?
    jim

    jim

    2 years ago
    This API is going to change slightly, but basically, the Composer will accept some classes (like Android Views 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.
    wasyl

    wasyl

    2 years ago
    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 🙂
    jim

    jim

    2 years ago
    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.