From eb33c933c8bcb9a8421a6acdb7a51f261121be45 Mon Sep 17 00:00:00 2001 From: fabriziobertoglio1987 Date: Thu, 14 Apr 2022 18:04:11 +0800 Subject: [PATCH] fix annoucement delayed to next character Issue documented in comment https://github.com/facebook/react-native/pull/33468#discussion_r848162849 calling requestSendAccessibilityEvent fixes the issue the logic was taken from TextView#setError which calls notifyViewAccessibilityStateChangedIfNeeded https://github.com/aosp-mirror/platform_frameworks_base/blob/1ac46f932ef88a8f96d652580d8105e361ffc842/core/java/android/widget/TextView.java#L7284 after some testing, calling the requestSendAccessibilityEvent on the parent view fixed the issue ``` mParent.requestSendAccessibilityEvent(this, event) ``` https://github.com/aosp-mirror/platform_frameworks_base/blob/1ac46f932ef88a8f96d652580d8105e361ffc842/core/java/android/view/View.java#L13710 --- .../react/views/textinput/ReactEditText.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java index 05c267e0580011..5b9d178320e76a 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java @@ -30,6 +30,7 @@ import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; +import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; @@ -171,6 +172,14 @@ public void onInitializeAccessibilityNodeInfo( } } + @Override + public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) { + super.onInitializeAccessibilityEvent(host, event); + if (((View) host).getParent() != null) { + ((View) host).getParent().requestSendAccessibilityEvent(host, event); + } + } + @Override public boolean performAccessibilityAction(View host, int action, Bundle args) { if (action == AccessibilityNodeInfo.ACTION_CLICK) { @@ -527,11 +536,12 @@ public int incrementAndGetEventCounter() { */ public void maybeSetAccessibilityError( int eventCounter, @Nullable String accessibilityErrorMessage) { - if (!canUpdateWithEventCount(eventCounter) || accessibilityErrorMessage == null) { + if (!canUpdateWithEventCount(eventCounter)) { return; } - announceForAccessibility("Invalid input " + accessibilityErrorMessage); - setTag(R.id.accessibility_error, null); + + setTag(R.id.accessibility_error, accessibilityErrorMessage); + sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); } public void maybeSetTextFromJS(ReactTextUpdate reactTextUpdate) {