Function

Composition

This method is the way to initiate a composition.

CustomTreeComposition

@Suppress("unused")
@Sampled
fun CustomTreeComposition() {
    // Provided we have a tree with a node base type like the following
    abstract class Node {
        val children = mutableListOf<Node>()
    }

    // We would implement an Applier class like the following, which would teach compose how to
    // manage a tree of Nodes.
    class NodeApplier(root: Node) : AbstractApplier<Node>(root) {
        override fun insertTopDown(index: Int, instance: Node) {
            current.children.add(index, instance)
        }

        override fun insertBottomUp(index: Int, instance: Node) {
            // Ignored as the tree is built top-down.
        }

        override fun remove(index: Int, count: Int) {
            current.children.remove(index, count)
        }

        override fun move(from: Int, to: Int, count: Int) {
            current.children.move(from, to, count)
        }

        override fun onClear() {
            root.children.clear()
        }
    }

    // A function like the following could be created to create a composition provided a root Node.
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: