From 898124541c314e77ea80a229f4630a0e8fd1fdd4 Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Fri, 30 Aug 2019 19:02:33 -0700 Subject: [PATCH] Support `sendAccessibilityEvent` in Fabric Summary: Support for `sendAccessibilityEvent` in the FabricUIManager. Reviewed By: shergin Differential Revision: D17142507 fbshipit-source-id: 5c131d7caa1e4189fd41ecfb558d0027394b6a15 --- .../com/facebook/react/bridge/UIManager.java | 8 +++++ .../react/fabric/FabricUIManager.java | 8 +++++ .../fabric/mounting/MountingManager.java | 14 +++++++++ .../mountitems/SendAccessibilityEvent.java | 30 +++++++++++++++++++ .../react/uimanager/UIManagerModule.java | 9 +++++- 5 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/SendAccessibilityEvent.java diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/UIManager.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/UIManager.java index b1c51c6ed73..2b6fb107efd 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/UIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/UIManager.java @@ -53,4 +53,12 @@ public interface UIManager extends JSIModule, PerformanceCounter { * @param props {@link ReadableMap} props that should be immediately updated in view */ void synchronouslyUpdateViewOnUIThread(int reactTag, ReadableMap props); + + /** + * Dispatch an accessibility event to a view asynchronously. + * + * @param reactTag + * @param eventType + */ + void sendAccessibilityEvent(int reactTag, int eventType); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index 2bfa8d17798..0e278e9003f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -51,6 +51,7 @@ import com.facebook.react.fabric.mounting.mountitems.InsertMountItem; import com.facebook.react.fabric.mounting.mountitems.MountItem; import com.facebook.react.fabric.mounting.mountitems.PreAllocateViewMountItem; import com.facebook.react.fabric.mounting.mountitems.RemoveMountItem; +import com.facebook.react.fabric.mounting.mountitems.SendAccessibilityEvent; import com.facebook.react.fabric.mounting.mountitems.UpdateEventEmitterMountItem; import com.facebook.react.fabric.mounting.mountitems.UpdateLayoutMountItem; import com.facebook.react.fabric.mounting.mountitems.UpdateLocalDataMountItem; @@ -566,6 +567,13 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { } } + @Override + public void sendAccessibilityEvent(int reactTag, int eventType) { + synchronized (mMountItemsLock) { + mMountItems.add(new SendAccessibilityEvent(reactTag, eventType)); + } + } + /** * Set the JS responder for the view associated with the tags received as a parameter. * diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java index f48548fbe1d..5c668434c60 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java @@ -143,6 +143,20 @@ public class MountingManager { viewState.mViewManager.receiveCommand(viewState.mView, commandId, commandArgs); } + public void sendAccessibilityEvent(int reactTag, int eventType) { + ViewState viewState = getViewState(reactTag); + + if (viewState.mViewManager == null) { + throw new IllegalStateException("Unable to find viewState manager for tag " + reactTag); + } + + if (viewState.mView == null) { + throw new IllegalStateException("Unable to find viewState view for tag " + reactTag); + } + + viewState.mView.sendAccessibilityEvent(eventType); + } + @SuppressWarnings("unchecked") // prevents unchecked conversion warn of the type private static ViewGroupManager getViewGroupManager(ViewState viewState) { if (viewState.mViewManager == null) { diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/SendAccessibilityEvent.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/SendAccessibilityEvent.java new file mode 100644 index 00000000000..633d1095a80 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/SendAccessibilityEvent.java @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. + * + *

This source code is licensed under the MIT license found in the LICENSE file in the root + * directory of this source tree. + */ +package com.facebook.react.fabric.mounting.mountitems; + +import com.facebook.react.fabric.mounting.MountingManager; + +public class SendAccessibilityEvent implements MountItem { + + private final int mReactTag; + private final int mEventType; + + public SendAccessibilityEvent(int reactTag, int eventType) { + mReactTag = reactTag; + mEventType = eventType; + } + + @Override + public void execute(MountingManager mountingManager) { + mountingManager.sendAccessibilityEvent(mReactTag, mEventType); + } + + @Override + public String toString() { + return "SendAccessibilityEvent [" + mReactTag + "] " + mEventType; + } +} diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java index 1668f11d019..db8f05286f2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java @@ -796,7 +796,14 @@ public class UIManagerModule extends ReactContextBaseJavaModule @ReactMethod public void sendAccessibilityEvent(int tag, int eventType) { - mUIImplementation.sendAccessibilityEvent(tag, eventType); + int uiManagerType = ViewUtil.getUIManagerType(tag); + if (uiManagerType == FABRIC) { + UIManager fabricUIManager = + UIManagerHelper.getUIManager(getReactApplicationContext(), uiManagerType); + fabricUIManager.sendAccessibilityEvent(tag, eventType); + } else { + mUIImplementation.sendAccessibilityEvent(tag, eventType); + } } /**