Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
React-Native 0.65 compatibility / Forward-port Accessibility to react…
Browse files Browse the repository at this point in the history
…-native 0.60 API

React-Native 0.59 -> 0.60 changed a lot of the AccessibilityInfo API, and this does a straight forward-port of existing functionality (screen reader status detection) to the new API.

Here is the related PR facebook/react-native-website#835

And the doc with new APIs https://facebook.github.io/react-native/docs/accessibilityinfo

This depends on the PR here for types I believe DefinitelyTyped/DefinitelyTyped#37486

There is an opportunity to also expand API coverage to cover the other new accessibility features react-native exposes but if this is desired it might be best to do it separately? Additionally the majority are iOS-specific so if I proposed that change I'd need some guidance.

Fixes microsoft#1319
  • Loading branch information
aajahid authored Jul 18, 2022
2 parents 14c9f14 + 16395d0 commit 2570150
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/native-common/Accessibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ export class Accessibility extends CommonAccessibility {
constructor() {
super();

let initialStateChanged = false;
let initialScreenReaderState = false;

// Some versions of RN don't support this interface.
if (RN.AccessibilityInfo) {
// Subscribe to an event to get notified when screen reader is enabled or disabled.
RN.AccessibilityInfo.addEventListener('change', (isEnabled: boolean) => {
initialStateChanged = true;
RN.AccessibilityInfo.addEventListener('screenReaderChanged', (isEnabled: boolean) => {
initialScreenReaderState = true;
this._updateScreenReaderStatus(isEnabled);
});

// Fetch initial state.
RN.AccessibilityInfo.fetch().then(isEnabled => {
if (!initialStateChanged) {
RN.AccessibilityInfo.isScreenReaderEnabled().then(isEnabled => {
if (!initialScreenReaderState) {
this._updateScreenReaderStatus(isEnabled);
}
}).catch(err => {
if (AppConfig.isDevelopmentMode()) {
console.error('Accessibility: RN.AccessibilityInfo.fetch failed');
console.error('Accessibility: RN.AccessibilityInfo.isScreenReaderEnabled failed');
}
});
}
Expand Down

0 comments on commit 2570150

Please sign in to comment.