Content will be updated
This page was moved from the old website without any change and might be updated
All components support content description by default. This means all layout builders have a prop of type
Setting a content description on any component is as simple as:
The content description set here has the same semantics as when it is set on an Android view.
Mount Specs can implement their own accessibility support by implementing an
@OnPopulateAccessibilityNode method. This method accepts an
AccessibilityNodeInfoCompat argument as well as any props that are specified on the spec method.
For example, accessibility for
Text is specified using the following method:
This is only applicable for components which mount drawables, since if the component mounts a view, the support is built-in.
On more complex mount specs that need to expose extra nodes to the accessibility framework, you'll have to implement three extra methods with the following annotations:
- GetExtraAccessibilityNodesCount: Returns number of extra accessibility nodes exposed by the component.
- OnPopulateExtraAccessibilityNode: Populates the extra accessibility node with the given bounds.
All components support a set of events corresponding to
These events have attributes for each parameter of the corresponding
AccessibilityDelegateCompat method and an additional parameter of type
superDelegate, which allows you to explicitly call
View's default implementation of accessibility methods where necessary.
Here is an overview of the supported events:
Setting a handler for any of these events will result in an
AccessibilityDelegate being set on the mounted
View, which will call your event handler when the corresponding method is called.
Whenever a method for which you haven't supplied an event handler is called, the delegate will defer to the Android
View's default implementation (equivalent to calling
For example, here are the steps for overriding
onInitializeAccessibilityNodeInfo for a component:
- Implementing an event handler
- Setting that event handler on a component:
One of the best features of
AccessibilityDelegates in general is their reusability even across different types of
Views. This can also be achieved within Litho by creating a wrapper spec that takes in a component and adds the desired event handlers. For example, let's say we want to have a Component that appends "please" to every
AccessibilityEvent that it announces.
Now you can replace any usages of your component with
Heading is an accessibility property and will help the users to choose to "Navigate by Headings" and ignore scrolling through each and every subitem under a heading. "Navigate based on Heading" can be selected from "Local Context Menu" when talkback is on. Talkback gesture for "Local Context Menu" is Swipe up then right. Making any component an Accessibility Header is as simple as: