Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] adding sendAccessibilityEvent to AccNodeInfo #3438

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
32 changes: 25 additions & 7 deletions docs/accessibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,33 @@ The `AccessibilityInfo` API allows you to determine whether or not a screen read

## Sending Accessibility Events <div class="label android">Android</div>

Sometimes it is useful to trigger an accessibility event on a UI component (i.e. when a custom view appears on a screen or set accessibility focus to a view). Native UIManager module exposes a method ‘sendAccessibilityEvent’ for this purpose. It takes two arguments: view tag and a type of an event. The supported event types are `typeWindowStateChanged`, `typeViewFocused` and `typeViewClicked`.
Sometimes it is useful to trigger an accessibility event on a UI component (i.e. when a custom view appears on a screen or set accessibility focus to a view). Native FabricUIManager module exposes a method `sendAccessibilityEvent` for this purpose. It takes two arguments: `handle` and `eventType`.
The supported event types are `typeWindowStateChanged`, `typeViewFocused`, and `typeViewClicked`.
Android also supports `viewHoverEnter`.

```tsx
import {Platform, UIManager, findNodeHandle} from 'react-native';

if (Platform.OS === 'android') {
UIManager.sendAccessibilityEvent(
findNodeHandle(this),
UIManager.AccessibilityEventTypes.typeViewFocused,
function SetAccessibilityFocusExample(props: Props) {
const myRef = React.useRef<React.ElementRef<
typeof Text
> | null>(null);

const onPress = () => {
if (myRef && myRef.current) {
AccessibilityInfo.sendAccessibilityEvent(
myRef.current,
'focus',
);
}
};

return (
<View>
<Text ref={myRef}>
SetAccessibilityFocus on native element. This should get
focus after clicking the button!
</Text>
<Button title={'Click'} onPress={onPress} />
</View>
);
}
```
Expand Down
17 changes: 17 additions & 0 deletions docs/accessibilityinfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,22 @@ Query whether reduce motion and prefer cross-fade transitions settings are curre

---

### `sendAccessibilityEvent()` <div class="label android">Android</div>

```jsx
static sendAccessibilityEvent(handle, eventType)
```

Sometimes it is helpful to trigger an accessibility event on a UI component (i.e. when a custom view appears on a screen or set accessibility focus to a view). Native FabricUIManager module exposes a method `sendAccessibilityEvent` for this purpose. It takes two arguments: `node` and `eventType`.

The supported event types are `typeWindowStateChanged`, `typeViewFocused`, and `typeViewClicked`.
Android also supports `viewHoverEnter`.

> **Notes**: Make sure that any `View` you want to receive the accessibility focus has `accessible={true}`.
> To avoid issues with TalkBack and Modal component, use `viewHoverEnter` (more info in issue [#30097](https://github.com/facebook/react-native/issues/30097#issuecomment-1285927266)).

---

### `setAccessibilityFocus()`

```tsx
Expand All @@ -398,3 +414,4 @@ Set accessibility focus to a React component.
On Android, this calls `UIManager.sendAccessibilityEvent` method with passed `reactTag` and `UIManager.AccessibilityEventTypes.typeViewFocused` arguments.

> **Note**: Make sure that any `View` you want to receive the accessibility focus has `accessible={true}`.
> **Deprecated.** Use the [sendAccessibilityEvent](#sendAccessibilityEvent) on Fabric