public class SemanticsPropertyKey<T>(
/** The name of the property. Should be the same as the constant from which it is accessed. */
public val name: String,
internal val mergePolicy: (T?, T) -> T? = { parentValue, childValue ->
parentValue ?: childValue
},
)
SemanticsPropertyKey is the infrastructure for setting key/value pairs inside semantics blocks in a type-safe way. Each key has one particular statically defined value type T.
Functions
merge
public fun merge(parentValue: T?, childValue: T): T?
Method implementing the semantics merge policy of a particular key.
When mergeDescendants is set on a semantics node, then this function will called for each descendant node of a given key in depth-first-search order. The parent value accumulates the result of merging the values seen so far, similar to reduce().
The default implementation returns the parent value if one exists, otherwise uses the child element. This means by default, a SemanticsNode with mergeDescendants = true winds up with the first value found for each key in its subtree in depth-first-search order.
getValue
public final operator fun getValue(
thisRef: SemanticsPropertyReceiver,
property: KProperty<*>,
): T
Throws UnsupportedOperationException. Should not be called.
setValue
public final operator fun setValue(
thisRef: SemanticsPropertyReceiver,
property: KProperty<*>,
value: T,
)
toString
override fun toString(): String