Skip to content

Commit

Permalink
BridgelessUIManager: Finish sendAccessibilityEvent
Browse files Browse the repository at this point in the history
Summary: Changelog: [Internal]

Reviewed By: dmytrorykun

Differential Revision: D52383282

fbshipit-source-id: 791cca056ebbe2bdf16082985a37b6df6724088b
  • Loading branch information
RSNara authored and facebook-github-bot committed Jan 10, 2024
1 parent 0bb1a5a commit 7effa25
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions packages/react-native/Libraries/ReactNative/BridgelessUIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,52 @@ const UIManagerJSPlatformAPIs = Platform.select({
);
}
},
// Please use AccessibilityInfo.sendAccessibilityEvent instead.
// See SetAccessibilityFocusExample in AccessibilityExample.js for a migration example.
sendAccessibilityEvent: (reactTag: ?number, eventType: number): void => {
raiseSoftError('sendAccessibilityEvent');
if (reactTag == null) {
console.error(
`sendAccessibilityEvent() dropping event: Cannot be called with ${String(
reactTag,
)} reactTag`,
);
return;
}

// Keep this in sync with java:FabricUIManager.sendAccessibilityEventFromJS
// and legacySendAccessibilityEvent.android.js
const AccessibilityEvent = {
TYPE_VIEW_FOCUSED: 0x00000008,
TYPE_WINDOW_STATE_CHANGED: 0x00000020,
TYPE_VIEW_CLICKED: 0x00000001,
TYPE_VIEW_HOVER_ENTER: 0x00000080,
};

let eventName = null;
if (eventType === AccessibilityEvent.TYPE_VIEW_FOCUSED) {
eventName = 'focus';
} else if (eventType === AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
eventName = 'windowStateChange';
} else if (eventType === AccessibilityEvent.TYPE_VIEW_CLICKED) {
eventName = 'click';
} else if (eventType === AccessibilityEvent.TYPE_VIEW_HOVER_ENTER) {
eventName = 'viewHoverEnter';
} else {
console.error(
`sendAccessibilityEvent() dropping event: Called with unsupported eventType: ${eventType}`,
);
return;
}

const FabricUIManager = nullthrows(getFabricUIManager());
const shadowNode =
FabricUIManager.findShadowNodeByTag_DEPRECATED(reactTag);
if (!shadowNode) {
console.error(
`sendAccessibilityEvent() dropping event: Cannot find view with tag #${reactTag}`,
);
return;
}

FabricUIManager.sendAccessibilityEvent(shadowNode, eventName);
},
showPopupMenu: (
reactTag: ?number,
Expand Down

0 comments on commit 7effa25

Please sign in to comment.