Skip to content

Commit 03a125c

Browse files
committed
refactoring logic parsing accRole to TtsSpan TYPES
1 parent e215baa commit 03a125c

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

Libraries/Components/View/ViewAccessibility.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import type {SyntheticEvent} from '../../Types/CoreEventTypes';
1414

15-
export type AccessibilityUnit = 'none' | 'verbatim';
1615
// This must be kept in sync with the AccessibilityRolesMask in RCTViewManager.m
1716
export type AccessibilityRole =
1817
| 'none'

ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.facebook.react.uimanager.events.EventDispatcher;
4646
import com.facebook.react.uimanager.util.ReactFindViewUtil;
4747
import com.facebook.react.views.text.ReactSpan;
48+
import com.facebook.react.views.text.ReactTtsSpan;
4849
import java.util.ArrayList;
4950
import java.util.HashMap;
5051
import java.util.List;
@@ -158,7 +159,7 @@ public static String getValue(AccessibilityRole role) {
158159
case GRID:
159160
return "android.widget.GridView";
160161
case VERBATIM:
161-
return "android.type.verbatim";
162+
return ReactTtsSpan.TYPE_VERBATIM;
162163
case NONE:
163164
case LINK:
164165
case SUMMARY:

ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.facebook.react.uimanager.LayoutShadowNode;
2626
import com.facebook.react.uimanager.NativeViewHierarchyOptimizer;
2727
import com.facebook.react.uimanager.PixelUtil;
28+
import com.facebook.react.uimanager.ReactAccessibilityDelegate.AccessibilityRole;
2829
import com.facebook.react.uimanager.ReactShadowNode;
2930
import com.facebook.react.uimanager.ViewProps;
3031
import com.facebook.react.uimanager.annotations.ReactProp;
@@ -184,10 +185,10 @@ private static void buildSpannedFromShadowNode(
184185
ops.add(
185186
new SetSpanOperation(start, end, new ReactClickableSpan(textShadowNode.getReactTag())));
186187
}
187-
if (textShadowNode.mIsAccessibilityUnit && Build.VERSION.SDK_INT >= 21) {
188+
if (textShadowNode.mAccessibilityUnit != null && Build.VERSION.SDK_INT >= 21) {
188189
ops.add(
189190
new SetSpanOperation(
190-
start, end, new ReactTtsSpan.Builder(textShadowNode.mAccessibilityRole).build()));
191+
start, end, new ReactTtsSpan.Builder(textShadowNode.mAccessibilityUnit).build()));
191192
}
192193
float effectiveLetterSpacing = textAttributes.getEffectiveLetterSpacing();
193194
if (!Float.isNaN(effectiveLetterSpacing)
@@ -330,9 +331,8 @@ protected Spannable spannedFromShadowNode(
330331
protected int mColor;
331332
protected boolean mIsBackgroundColorSet = false;
332333
protected int mBackgroundColor;
333-
protected String mAccessibilityRole;
334+
protected @Nullable String mAccessibilityUnit = null;
334335
protected boolean mIsAccessibilityLink = false;
335-
protected boolean mIsAccessibilityUnit;
336336

337337
protected int mNumberOfLines = UNSET;
338338
protected int mTextAlign = Gravity.NO_GRAVITY;
@@ -507,10 +507,11 @@ public void setBackgroundColor(@Nullable Integer color) {
507507
@ReactProp(name = ViewProps.ACCESSIBILITY_ROLE)
508508
public void setIsAccessibilityLink(@Nullable String accessibilityRole) {
509509
if (isVirtual()) {
510-
mAccessibilityRole = accessibilityRole;
510+
String roleClassName =
511+
AccessibilityRole.getValue(AccessibilityRole.fromValue(accessibilityRole));
511512
mIsAccessibilityLink = Objects.equals(accessibilityRole, "link");
512-
Set<String> TYPES = Set.of("verbatim", "date");
513-
mIsAccessibilityUnit = TYPES.contains(accessibilityRole);
513+
Set<String> UNIT_TYPES = Set.of(ReactTtsSpan.TYPE_VERBATIM, ReactTtsSpan.TYPE_DATE);
514+
mAccessibilityUnit = UNIT_TYPES.contains(roleClassName) ? roleClassName : null;
514515
markUpdated();
515516
}
516517
}

ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTtsSpan.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,7 @@ public static class Builder<C extends Builder<?>> {
2828
private PersistableBundle mArgs = new PersistableBundle();
2929

3030
public Builder(String type) {
31-
if (type == "verbatim") {
32-
mType = TYPE_VERBATIM;
33-
} else if (type == "date") {
34-
mType = TYPE_DATE;
35-
} else {
36-
mType = TYPE_TEXT;
37-
}
31+
mType = type;
3832
}
3933

4034
public ReactTtsSpan build() {

0 commit comments

Comments
 (0)