Skip to content

Commit

Permalink
AccessibilityInfo.announceForAccessibility (#24746)
Browse files Browse the repository at this point in the history
Summary:
AccessibilityInfo.announceForAccessibility is currently only available on iOS. I've added the Android specific implementation, updated RNTester, and the documentation.

[Android] [Added] - Added AccessibilityInfo.announceForAccessibility for Android
[General] [Added] - RNTester example for AccessibilityInfo.announceForAccessibility
Pull Request resolved: #24746

Differential Revision: D15258054

Pulled By: cpojer

fbshipit-source-id: 3e057a5c32b28e30ea2ee74a18854b012cd2dbfd
  • Loading branch information
adkenyon authored and facebook-github-bot committed May 8, 2019
1 parent 9261035 commit 09f17a4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ const AccessibilityInfo = {
UIManager.AccessibilityEventTypes.typeViewFocused,
);
},

/**
* Post a string to be announced by the screen reader.
*
* See http://facebook.github.io/react-native/docs/accessibilityinfo.html#announceforaccessibility
*/
announceForAccessibility: function(announcement: string): void {
RCTAccessibilityInfo.announceForAccessibility(announcement);
},
};

module.exports = AccessibilityInfo;
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ const AccessibilityInfo = {
/**
* Post a string to be announced by the screen reader.
*
* @platform ios
*
* See http://facebook.github.io/react-native/docs/accessibilityinfo.html#announceforaccessibility
*/
announceForAccessibility: function(announcement: string): void {
Expand Down
22 changes: 22 additions & 0 deletions RNTester/js/AccessibilityExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,22 @@ class ScreenReaderStatusExample extends React.Component<{}> {
}
}

class AnnounceForAccessibility extends React.Component<{}> {
_handleOnPress = () =>
AccessibilityInfo.announceForAccessibility('Announcement Test');

render() {
return (
<View>
<Button
onPress={this._handleOnPress}
title="Announce for Accessibility"
/>
</View>
);
}
}

exports.title = 'Accessibility';
exports.description = 'Examples of using Accessibility APIs.';
exports.examples = [
Expand All @@ -473,4 +489,10 @@ exports.examples = [
return <ScreenReaderStatusExample />;
},
},
{
title: 'Check if the screen reader announces',
render(): React.Element<typeof AnnounceForAccessibility> {
return <AnnounceForAccessibility />;
},
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;

import com.facebook.react.bridge.Callback;
Expand Down Expand Up @@ -170,4 +171,18 @@ public void onCatalystInstanceDestroy() {
@Override
public void onHostDestroy() {
}

@ReactMethod
public void announceForAccessibility(String message) {
if (mAccessibilityManager == null || !mAccessibilityManager.isEnabled()) {
return;
}

AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_ANNOUNCEMENT);
event.getText().add(message);
event.setClassName(AccessibilityInfoModule.class.getName());
event.setPackageName(getReactApplicationContext().getPackageName());

mAccessibilityManager.sendAccessibilityEvent(event);
}
}

0 comments on commit 09f17a4

Please sign in to comment.