{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

SemanticsPropertyKey

public final class SemanticsPropertyKey<T extends Object>


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.

Summary

Public constructors

<T extends Object> SemanticsPropertyKey(
    @NonNull String name,
    @NonNull Function2<T, @NonNull T, T> mergePolicy
)

Public methods

final @NonNull String

The name of the property.

final @NonNull T
getValue(
    @NonNull SemanticsPropertyReceiver thisRef,
    @NonNull KProperty<@NonNull ?> property
)

Throws UnsupportedOperationException.

final T
merge(T parentValue, @NonNull T childValue)

Method implementing the semantics merge policy of a particular key.

final void
setValue(
    @NonNull SemanticsPropertyReceiver thisRef,
    @NonNull KProperty<@NonNull ?> property,
    @NonNull T value
)
@NonNull String

Public constructors

SemanticsPropertyKey

public <T extends Object> SemanticsPropertyKey(
    @NonNull String name,
    @NonNull Function2<T, @NonNull T, T> mergePolicy
)

Public methods

getName

public final @NonNull String getName()

The name of the property. Should be the same as the constant from which it is accessed.

getValue

public final @NonNullgetValue(
    @NonNull SemanticsPropertyReceiver thisRef,
    @NonNull KProperty<@NonNull ?> property
)

Throws UnsupportedOperationException. Should not be called.

merge

public final T merge(T parentValue, @NonNull T childValue)

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.

setValue

public final void setValue(
    @NonNull SemanticsPropertyReceiver thisRef,
    @NonNull KProperty<@NonNull ?> property,
    @NonNull T value
)

toString

public @NonNull String toString()