Android implementation of sendAccessibilityEvent

Summary:
This is the Android native implementation of sendAccessibilityEvent for Fabric.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D25852418

fbshipit-source-id: cb51e667a7f673da6b9c9e539770225b02bdc902
This commit is contained in:
Joshua Gross
2021-01-08 18:10:59 -08:00
committed by Facebook GitHub Bot
parent c15f907f67
commit 055d029bc0
3 changed files with 42 additions and 0 deletions
@@ -25,6 +25,7 @@ import android.content.Context;
import android.graphics.Point;
import android.os.SystemClock;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import androidx.annotation.AnyThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -1005,6 +1006,23 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
addMountItem(new SendAccessibilityEvent(reactTag, eventType));
}
@AnyThread
@ThreadConfined(ANY)
public void sendAccessibilityEventFromJS(int reactTag, String eventTypeJS) {
int eventType;
if ("focus".equals(eventTypeJS)) {
eventType = AccessibilityEvent.TYPE_VIEW_FOCUSED;
} else if ("windowStateChange".equals(eventTypeJS)) {
eventType = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
} else if ("click".equals(eventTypeJS)) {
eventType = AccessibilityEvent.TYPE_VIEW_CLICKED;
} else {
throw new IllegalArgumentException(
"sendAccessibilityEventFromJS: invalid eventType " + eventTypeJS);
}
addMountItem(new SendAccessibilityEvent(reactTag, eventType));
}
/**
* Set the JS responder for the view associated with the tags received as a parameter.
*
@@ -1071,6 +1071,26 @@ void Binding::schedulerDidDispatchCommand(
localJavaUIManager, shadowView.tag, command.get(), argsArray.get());
}
void Binding::schedulerDidSendAccessibilityEvent(
const ShadowView &shadowView,
std::string const &eventType) {
jni::global_ref<jobject> localJavaUIManager = getJavaUIManager();
if (!localJavaUIManager) {
LOG(ERROR)
<< "Binding::schedulerDidDispatchCommand: JavaUIManager disappeared";
return;
}
local_ref<JString> eventTypeStr = make_jstring(eventType);
static auto sendAccessibilityEventFromJS =
jni::findClassStatic(Binding::UIManagerJavaDescriptor)
->getMethod<void(jint, jstring)>("sendAccessibilityEventFromJS");
sendAccessibilityEventFromJS(
localJavaUIManager, shadowView.tag, eventTypeStr.get());
}
void Binding::schedulerDidSetJSResponder(
SurfaceId surfaceId,
const ShadowView &shadowView,
@@ -136,6 +136,10 @@ class Binding : public jni::HybridClass<Binding>,
std::string const &commandName,
folly::dynamic const args) override;
void schedulerDidSendAccessibilityEvent(
const ShadowView &shadowView,
std::string const &eventType) override;
void schedulerDidSetJSResponder(
SurfaceId surfaceId,
const ShadowView &shadowView,