SemanticsModifierNode


A Modifier.Node that adds semantics key/value for use in testing, accessibility, and similar use cases.

This is the androidx.compose.ui.Modifier.Node equivalent of androidx.compose.ui.semantics.SemanticsModifier

Summary

Public functions

Unit

Add semantics key/value pairs to the layout node, for use in testing, accessibility, etc.

Cmn

Public properties

open Boolean

Clears the semantics of all the descendant nodes and sets new semantics.

Cmn
open Boolean

Whether the semantic information provided by this node and its descendants should be treated as one logical entity.

Cmn

Extension functions

Unit

Invalidate semantics associated with this node.

Cmn

Inherited functions

From androidx.compose.ui.node.DelegatableNode
open Unit

Invoked when the density changes for this node.

Cmn
open Unit

Invoked when the layout direction changes for this node.

Cmn

Inherited properties

From androidx.compose.ui.node.DelegatableNode
Modifier.Node

A reference of the Modifier.Node that holds this node's position in the node hierarchy.

Cmn

Public functions

applySemantics

fun SemanticsPropertyReceiver.applySemantics(): Unit

Add semantics key/value pairs to the layout node, for use in testing, accessibility, etc.

The SemanticsPropertyReceiver provides "key = value"-style setters for any SemanticsPropertyKey. Additionally, chaining multiple semantics modifiers is also a supported style.

The resulting semantics produce two SemanticsNode trees:

The "unmerged tree" rooted at SemanticsOwner.unmergedRootSemanticsNode has one SemanticsNode per layout node which has any SemanticsModifierNode on it. This SemanticsNode contains all the properties set in all the SemanticsModifierNodes on that node.

The "merged tree" rooted at SemanticsOwner.rootSemanticsNode has equal-or-fewer nodes: it simplifies the structure based on shouldMergeDescendantSemantics and shouldClearDescendantSemantics. For most purposes (especially accessibility, or the testing of accessibility), the merged semantics tree should be used.

Public properties

shouldClearDescendantSemantics

open val shouldClearDescendantSemanticsBoolean

Clears the semantics of all the descendant nodes and sets new semantics.

In the merged semantics tree, this clears the semantic information provided by the node's descendants (but not those of the layout node itself, if any) In the unmerged tree, the semantics node is marked with "SemanticsConfiguration.isClearingSemantics", but nothing is actually cleared.

Compose's default semantics provide baseline usability for screen-readers, but this can be used to provide a more polished screen-reader experience: for example, clearing the semantics of a group of tiny buttons, and setting equivalent actions on the card containing them.

shouldMergeDescendantSemantics

open val shouldMergeDescendantSemanticsBoolean

Whether the semantic information provided by this node and its descendants should be treated as one logical entity. Most commonly set on screen-reader-focusable items such as buttons or form fields. In the merged semantics tree, all descendant nodes (except those themselves marked shouldMergeDescendantSemantics) will disappear from the tree, and their properties will get merged into the parent's configuration (using a merging algorithm that varies based on the type of property -- for example, text properties will get concatenated, separated by commas). In the unmerged semantics tree, the node is simply marked with SemanticsConfiguration.isMergingSemanticsOfDescendants.

Extension functions

invalidateSemantics

fun SemanticsModifierNode.invalidateSemantics(): Unit

Invalidate semantics associated with this node. This will reset the SemanticsConfiguration associated with the layout node backing this modifier node, and will re-calculate it the next time the SemanticsConfiguration is read.