Skip to content

Commit

Permalink
Make AccessibilityInfo.setAccessibilityFocus cross platform (#20229)
Browse files Browse the repository at this point in the history
Summary:
Currently, `AccessibilityInfo.setAccessibilityFocus` is only available on iOS. The same behaviour can be achieved on Android by dispatching the proper accessibility event. I implemented the same function for Android, to make life slightly more convenient for the developer.

Today, developers must write something like this:
```
if (Platform.OS === 'ios') {
     AccessibilityInfo.setAccessibilityFocus(reactTag)
} else {
     UIManager.sendAccessibilityEvent(reactTag, 8)
}
```

With this change, the following is enough for both Android and iOS:
```
AccessibilityInfo.setAccessibilityFocus(reactTag)
```
Pull Request resolved: #20229

Differential Revision: D8874107

Pulled By: mdvacca

fbshipit-source-id: a6ffd7bb89ce56d6d65b06419633a71dcf3d0733
  • Loading branch information
draperunner authored and facebook-github-bot committed Jul 19, 2018
1 parent 7ff7572 commit be715ec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

const NativeModules = require('NativeModules');
const RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
const UIManager = require('UIManager');

const RCTAccessibilityInfo = NativeModules.AccessibilityInfo;

Expand Down Expand Up @@ -66,6 +67,18 @@ const AccessibilityInfo = {
listener.remove();
_subscriptions.delete(handler);
},

/**
* Set accessibility focus to a react component.
*
* See http://facebook.github.io/react-native/docs/accessibilityinfo.html#setaccessibilityfocus
*/
setAccessibilityFocus: function(reactTag: number): void {
UIManager.sendAccessibilityEvent(
reactTag,
UIManager.AccessibilityEventTypes.typeViewFocused,
);
},
};

module.exports = AccessibilityInfo;
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ const AccessibilityInfo = {
/**
* Set accessibility focus to a react component.
*
* @platform ios
*
* See http://facebook.github.io/react-native/docs/accessibilityinfo.html#setaccessibilityfocus
*/
setAccessibilityFocus: function(reactTag: number): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public static Map<String, Object> getConstants() {
MapBuilder.of(
"typeWindowStateChanged",
AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
"typeViewFocused",
AccessibilityEvent.TYPE_VIEW_FOCUSED,
"typeViewClicked",
AccessibilityEvent.TYPE_VIEW_CLICKED));

Expand Down

0 comments on commit be715ec

Please sign in to comment.