LazyTree

fun <T> LazyTree(root: TreeNode<T>, modifier: Modifier = Modifier, initiallyExpanded: Boolean = true, nodeContent: @Composable (node: TreeNode<T>, depth: Int, expanded: Boolean, toggle: () -> Unit) -> Unit)(source)

A lazily-rendered, expand/collapse tree for Compose Multiplatform. Only the currently-visible nodes are composed, so it scales to large trees. Expansion state is remembered internally, keyed by node identity.

LazyTree(root) { node, depth, expanded, toggle ->
Row(Modifier.padding(start = (depth * 16).dp).clickable(onClick = toggle)) {
if (!node.isLeaf) Text(if (expanded) "▾" else "▸")
Text(node.value.toString())
}
}

Parameters

root

the root of the tree to display.

modifier

the Modifier applied to the underlying LazyColumn.

initiallyExpanded

whether nodes start expanded.

nodeContent

renders a single node. Receives the node, its depth (root = 0), whether it is expanded, and a toggle callback that flips this node's expansion state.


fun <T> LazyTree(root: TreeNode<T>, modifier: Modifier = Modifier, initiallyExpanded: Boolean = true, indent: Dp = 16.dp, label: (T) -> String = { it.toString() })(source)

Convenience overload of LazyTree that renders each node with the built-in TreeNodeRow, so the common case is a single call:

LazyTree(root)

Use the overload that takes a nodeContent lambda when you need full control over a node's look.

Parameters

root

the root of the tree to display.

modifier

the Modifier applied to the underlying LazyColumn.

initiallyExpanded

whether nodes start expanded.

indent

the horizontal indentation applied per depth level.

label

maps a node's value to the text shown. Defaults to toString().