Support sendAccessibilityEvent in Fabric

Summary: Support for `sendAccessibilityEvent` in the FabricUIManager.

Reviewed By: shergin

Differential Revision: D17142507

fbshipit-source-id: 5c131d7caa1e4189fd41ecfb558d0027394b6a15
This commit is contained in:
Joshua Gross
2019-08-30 19:04:14 -07:00
committed by Facebook Github Bot
parent c80192c2ab
commit 898124541c
5 changed files with 68 additions and 1 deletions
@@ -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);
}
@@ -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.
*
@@ -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 <ViewGroup> type
private static ViewGroupManager<ViewGroup> getViewGroupManager(ViewState viewState) {
if (viewState.mViewManager == null) {
@@ -0,0 +1,30 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* <p>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;
}
}
@@ -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);
}
}
/**