SemanticsPropertyKey

Class

Common
class SemanticsPropertyKey<T>(
    /** The name of the property. Should be the same as the constant from which it is accessed. */
    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.

Secondary Constructors

internal constructor(name: String, isImportantForAccessibility: Boolean) : this(name) {
    this.isImportantForAccessibility = isImportantForAccessibility
}
internal constructor(
    name: String,
    isImportantForAccessibility: Boolean,
    mergePolicy: (T?, T) -> T?,
    accessibilityExtraKey: String? = null,
) : this(name, mergePolicy) {
    this.isImportantForAccessibility = isImportantForAccessibility
    this.accessibilityExtraKey = accessibilityExtraKey
}

Functions

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.

final operator fun getValue(thisRef: SemanticsPropertyReceiver, property: KProperty<*>): T

Throws UnsupportedOperationException. Should not be called.

final operator fun setValue(
        thisRef: SemanticsPropertyReceiver,
        property: KProperty<*>,
        value: T,
    )