45
45
import com .facebook .react .uimanager .events .Event ;
46
46
import com .facebook .react .uimanager .events .EventDispatcher ;
47
47
import com .facebook .react .uimanager .util .ReactFindViewUtil ;
48
+ import com .facebook .react .views .text .ReactSpan ;
48
49
import com .facebook .react .views .text .ReactTtsSpan ;
49
50
import java .util .ArrayList ;
50
51
import java .util .HashMap ;
@@ -671,10 +672,10 @@ protected boolean onPerformActionForVirtualView(
671
672
public static class AccessibilityLinks {
672
673
private final List <AccessibleLink > mLinks ;
673
674
674
- public AccessibilityLinks (ReactTtsSpan [] spans , Spannable text ) {
675
+ public AccessibilityLinks (ReactSpan [] spans , Spannable text ) {
675
676
ArrayList <AccessibleLink > links = new ArrayList <>();
676
677
for (int i = 0 ; i < spans .length ; i ++) {
677
- ReactTtsSpan span = spans [i ];
678
+ ReactSpan span = spans [i ];
678
679
int start = text .getSpanStart (span );
679
680
int end = text .getSpanEnd (span );
680
681
// zero length spans, and out of range spans should not be included.
@@ -683,39 +684,18 @@ public AccessibilityLinks(ReactTtsSpan[] spans, Spannable text) {
683
684
}
684
685
685
686
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 ;
713
698
}
714
-
715
- final AccessibleLink link = new AccessibleLink ();
716
- link .description = text .subSequence (start , end ).toString ();
717
- link .start = start ;
718
- link .end = end ;
719
699
720
700
// ID is the reverse of what is expected, since the ClickableSpans are returned in reverse
721
701
// 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() {
757
737
758
738
private static class AccessibleLink {
759
739
public String description ;
760
- public ReactTtsSpan span ;
740
+ public ReactSpan span ;
761
741
public int start ;
762
742
public int end ;
763
743
public int id ;
0 commit comments