Skip to content

Commit

Permalink
fix annoucement delayed to next character
Browse files Browse the repository at this point in the history
Issue documented in comment #33468 (comment)

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
  • Loading branch information
fabOnReact committed Apr 14, 2022
1 parent 994089c commit eb33c93
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit eb33c93

Please sign in to comment.