SlotEditor
open class SlotEditor
kotlin.Any | |
↳ | androidx.compose.SlotEditor |
A gap buffer implementation of the composition slot space. A slot space can be thought of as a custom List<Any?> that optimizes around inserts and removes.
Slots stores slots, groups, and nodes.
Slot - A slot is the primitive base type of the slot space. It is of type Any? and can hold any value. Group - A group is a keyed group of slots. The group counts the number of slots and nodes it contains. Node - A node is a special group that is counted by the containing groups.
All groups and nodes are just grouping of slots and use slots to describe the groups. At the root of a slot space is a group. Groups count the number nodes that are in the group. A node only counts as one node in its group regardless of the number of nodes it contains.
ASIDE: The intent is that groups represent memoized function calls and nodes represent views. For example:
import android.widget.LinearLayout LinearLayout { Contact(contact = jim) Contact(contact = bob) }
the LinearLayout
here would be a node (the linear layout view). The node contains the
groups for the child views of the linear layout.
If contact's composition looks like:
import android.widget.TextView @Composable fun Contact(contact: Contact) { TextView(text = contact.name) TextView(text = contact.email) }
then composing contact into the linear layout would add two views to the linear layout's children. The composition of contact creates groups, one for each text view. The groups for each contact would be able to report that it produces two views (that is the group created for Contact has two nodes). Summing the nodes in the group produces the number of views (as each node corresponds to a view).
If the order of jim and bob change:
import android.widget.LinearLayout LinearLayout { Contact(contact = bob) Contact(contact = jim) }the previous result can be reused by moving the views generated bob's group before jim's (or visversa). A composition algorithm could use the key information for each group to determine if theycan be switched. For example, since the first contact's group has two nodes the compositionalgorithm can infer that the beginning of jim's views starts at 2 and contains 2 view. To movejim in front of bob, move the 2 views from offset 2 to offset 0. If contact is immutable, forexample, Contact would only need to be recomposed if the value of jim or bob change.
Summary
Public methods |
|
---|---|
Any? |
Get the value at an Anchor |
Any? |
Get the value at the index'th slot. |
Int |
Return the size of the group at index. |
Boolean |
Return true if the slot at index starts a gorup |
Properties |
|
---|---|
Int | |
Int |
Return the number of nodes in the group. |
Boolean |
Return true if the current slot starts a group |
Boolean |
Return true if the current slot starts a node. |
Int |
Get the number of nodes emitted to the group prior to the current slot. |
Int | |
Int |
Get the total number of nodes emitted in the group containing the current. |
SlotTable |
Public methods
groupSize
fun groupSize(index: Int): Int
Return the size of the group at index. isGroup(index) must be true of this will throw.
Properties
current
var current: Int
groupSize
val groupSize: Int
Return the number of nodes in the group. isGroup must be true or this will throw.
isNode
val isNode: Boolean
Return true if the current slot starts a node. A node is a kind of group so this will return true for isGroup as well.
nodeIndex
val nodeIndex: Int
Get the number of nodes emitted to the group prior to the current slot.
parentIndex
val parentIndex: Int
parentNodes
val parentNodes: Int
Get the total number of nodes emitted in the group containing the current.
table
val table: SlotTable