From 9c730f529874f6580d11bb7c75dc7a910fc51a79 Mon Sep 17 00:00:00 2001 From: fabriziobertoglio1987 Date: Fri, 29 Jul 2022 16:13:34 +0800 Subject: [PATCH] avoid focusing on parent and delegate focus to children https://github.com/facebook/react-native/issues/30850#issuecomment-1197763943 --- .../uimanager/ReactAccessibilityDelegate.java | 53 ++++--------------- .../Accessibility/AccessibilityExample.js | 4 +- 2 files changed, 14 insertions(+), 43 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.java index 3e6d1b36b08467..2328046441f38c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.java @@ -18,6 +18,7 @@ import android.text.Spanned; import android.text.style.AbsoluteSizeSpan; import android.text.style.ClickableSpan; +import android.util.Log; import android.view.View; import android.view.accessibility.AccessibilityEvent; import android.widget.TextView; @@ -30,19 +31,11 @@ import androidx.core.view.accessibility.AccessibilityNodeProviderCompat; import androidx.customview.widget.ExploreByTouchHelper; import com.facebook.react.R; -import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.Dynamic; -import com.facebook.react.bridge.ReactContext; -import com.facebook.react.bridge.ReactNoCrashSoftException; -import com.facebook.react.bridge.ReactSoftExceptionLogger; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableMapKeySetIterator; import com.facebook.react.bridge.ReadableType; -import com.facebook.react.bridge.UIManager; -import com.facebook.react.bridge.WritableMap; -import com.facebook.react.uimanager.events.Event; -import com.facebook.react.uimanager.events.EventDispatcher; import com.facebook.react.uimanager.util.ReactFindViewUtil; import java.util.ArrayList; import java.util.HashMap; @@ -348,6 +341,7 @@ public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) @Override public boolean performAccessibilityAction(View host, int action, Bundle args) { + /* if (mAccessibilityActionsMap.containsKey(action)) { final WritableMap event = Arguments.createMap(); event.putString("actionName", mAccessibilityActionsMap.get(action)); @@ -392,7 +386,8 @@ protected WritableMap getEventData() { } return true; } - return super.performAccessibilityAction(host, action, args); + */ + return true; } private static void setState( @@ -503,41 +498,15 @@ public static void resetDelegate( @Override protected int getVirtualViewAt(float x, float y) { - if (mAccessibilityLinks == null - || mAccessibilityLinks.size() == 0 - || !(mView instanceof TextView)) { - return INVALID_ID; - } - + Log.w("TESTING::ReactAccessibilityDelegate", "getVirtualViewAt"); + Log.w("TESTING::ReactAccessibilityDelegate", "x: " + (x)); + Log.w("TESTING::ReactAccessibilityDelegate", "y: " + (y)); TextView textView = (TextView) mView; - if (!(textView.getText() instanceof Spanned)) { - return INVALID_ID; - } - - Layout layout = textView.getLayout(); - if (layout == null) { - return INVALID_ID; - } - - x -= textView.getTotalPaddingLeft(); - y -= textView.getTotalPaddingTop(); - x += textView.getScrollX(); - y += textView.getScrollY(); - - int line = layout.getLineForVertical((int) y); - int charOffset = layout.getOffsetForHorizontal(line, x); - - ClickableSpan clickableSpan = getFirstSpan(charOffset, charOffset, ClickableSpan.class); - if (clickableSpan == null) { - return INVALID_ID; + if (mAccessibilityLinks != null || mAccessibilityLinks.size() > 0) { + Integer firstLinkId = mAccessibilityLinks.mLinks.get(mAccessibilityLinks.size() - 1).id; + return firstLinkId; } - - Spanned spanned = (Spanned) textView.getText(); - int start = spanned.getSpanStart(clickableSpan); - int end = spanned.getSpanEnd(clickableSpan); - - final AccessibilityLinks.AccessibleLink link = mAccessibilityLinks.getLinkBySpanPos(start, end); - return link != null ? link.id : INVALID_ID; + return INVALID_ID; } @Override diff --git a/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js b/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js index d4b14b5b78530d..ca08e5198a28ae 100644 --- a/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js +++ b/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js @@ -74,9 +74,11 @@ class AccessibilityExample extends React.Component<{}> { return ( - + Text's accessibilityLabel is the raw text itself unless it is set explicitly. + Link One + Link Two