Skip to content

Commit 145303e

Browse files
committed
remove code duplication
1 parent 08d6f43 commit 145303e

File tree

2 files changed

+15
-39
lines changed

2 files changed

+15
-39
lines changed

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

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.facebook.react.uimanager.events.Event;
4646
import com.facebook.react.uimanager.events.EventDispatcher;
4747
import com.facebook.react.uimanager.util.ReactFindViewUtil;
48+
import com.facebook.react.views.text.ReactSpan;
4849
import com.facebook.react.views.text.ReactTtsSpan;
4950
import java.util.ArrayList;
5051
import java.util.HashMap;
@@ -671,10 +672,10 @@ protected boolean onPerformActionForVirtualView(
671672
public static class AccessibilityLinks {
672673
private final List<AccessibleLink> mLinks;
673674

674-
public AccessibilityLinks(ReactTtsSpan[] spans, Spannable text) {
675+
public AccessibilityLinks(ReactSpan[] spans, Spannable text) {
675676
ArrayList<AccessibleLink> links = new ArrayList<>();
676677
for (int i = 0; i < spans.length; i++) {
677-
ReactTtsSpan span = spans[i];
678+
ReactSpan span = spans[i];
678679
int start = text.getSpanStart(span);
679680
int end = text.getSpanEnd(span);
680681
// zero length spans, and out of range spans should not be included.
@@ -683,39 +684,18 @@ public AccessibilityLinks(ReactTtsSpan[] spans, Spannable text) {
683684
}
684685

685686
final AccessibleLink link = new AccessibleLink();
686-
link.span = span;
687-
SpannableString spannableDescription = new SpannableString(text.subSequence(start, end));
688-
link.description = spannableDescription.toString();
689-
link.start = spannableDescription.getSpanStart(span);
690-
link.end = spannableDescription.getSpanEnd(span);
691-
692-
// ID is the reverse of what is expected, since the ClickableSpans are returned in reverse
693-
// order due to being added in reverse order. If we don't do this, focus will move to the
694-
// last link first and move backwards.
695-
//
696-
// If this approach becomes unreliable, we should instead look at their start position and
697-
// order them manually.
698-
link.id = spans.length - 1 - i;
699-
links.add(link);
700-
}
701-
mLinks = links;
702-
}
703-
704-
public AccessibilityLinks(ClickableSpan[] spans, Spannable text) {
705-
ArrayList<AccessibleLink> links = new ArrayList<>();
706-
for (int i = 0; i < spans.length; i++) {
707-
ClickableSpan span = spans[i];
708-
int start = text.getSpanStart(span);
709-
int end = text.getSpanEnd(span);
710-
// zero length spans, and out of range spans should not be included.
711-
if (start == end || start < 0 || end < 0 || start > text.length() || end > text.length()) {
712-
continue;
687+
if (span instanceof ReactTtsSpan) {
688+
link.span = span;
689+
SpannableString spannableDescription = new SpannableString(text.subSequence(start, end));
690+
link.description = spannableDescription.toString();
691+
link.start = spannableDescription.getSpanStart(span);
692+
link.end = spannableDescription.getSpanEnd(span);
693+
}
694+
if (span instanceof ClickableSpan) {
695+
link.description = text.subSequence(start, end).toString();
696+
link.start = start;
697+
link.end = end;
713698
}
714-
715-
final AccessibleLink link = new AccessibleLink();
716-
link.description = text.subSequence(start, end).toString();
717-
link.start = start;
718-
link.end = end;
719699

720700
// ID is the reverse of what is expected, since the ClickableSpans are returned in reverse
721701
// order due to being added in reverse order. If we don't do this, focus will move to the
@@ -757,7 +737,7 @@ public int size() {
757737

758738
private static class AccessibleLink {
759739
public String description;
760-
public ReactTtsSpan span;
740+
public ReactSpan span;
761741
public int start;
762742
public int end;
763743
public int id;

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import android.text.Spannable;
1616
import android.text.SpannableStringBuilder;
1717
import android.text.TextUtils;
18-
import android.util.Log;
1918
import android.view.Gravity;
2019
import androidx.annotation.Nullable;
2120
import com.facebook.infer.annotation.Assertions;
@@ -102,7 +101,6 @@ private static void buildSpannedFromShadowNode(
102101
boolean supportsInlineViews,
103102
Map<Integer, ReactShadowNode> inlineViews,
104103
int start) {
105-
Log.w("TESTING::ReactBaseTextShadowNode", "buildSpannedFromShadowNode");
106104

107105
TextAttributes textAttributes;
108106
if (parentTextAttributes != null) {
@@ -485,12 +483,10 @@ public void setColor(@Nullable Integer color) {
485483

486484
@ReactProp(name = ViewProps.BACKGROUND_COLOR, customType = "Color")
487485
public void setBackgroundColor(@Nullable Integer color) {
488-
Log.w("TESTING::ReactBaseTextShadowNode", "setBackgroundColor");
489486
// Background color needs to be handled here for virtual nodes so it can be incorporated into
490487
// the span. However, it doesn't need to be applied to non-virtual nodes because non-virtual
491488
// nodes get mapped to native views and native views get their background colors get set via
492489
// {@link BaseViewManager}.
493-
Log.w("TESTING::ReactBaseTextShadowNode", "isVirtual(): " + (isVirtual()));
494490
if (isVirtual()) {
495491
mIsBackgroundColorSet = (color != null);
496492
if (mIsBackgroundColorSet) {

0 commit comments

Comments
 (0)