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
  • Loading branch information
Abdullah Al Jahid committed Jul 18, 2022
1 parent 14c9f14 commit 16395d0
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 16395d0

Please sign in to comment.