Skip to content

Commit

Permalink
correctly spelling a span text
Browse files Browse the repository at this point in the history
  • Loading branch information
fabOnReact committed Oct 29, 2022
1 parent 216a30a commit 48a01d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
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;
Expand Down Expand Up @@ -587,37 +586,24 @@ protected void onPopulateNodeForVirtualView(
node.setBoundsInParent(getBoundsInParent(accessibleTextSpan));
node.setRoleDescription(mView.getResources().getString(R.string.link_description));
node.setClassName(AccessibilityRole.getValue(AccessibilityRole.BUTTON));
Log.w("TESTING::ReactAccessibilityDelegate", "mAccessibilitySpans: " + (mAccessibilitySpans));
if (mAccessibilitySpans == null) {
return;
}
final AccessibilityLinks.AccessibleLink ttsSpan =
mAccessibilitySpans.getLinkById(virtualViewId);
Log.w("TESTING::ReactAccessibilityDelegate", "ttsSpan: " + (ttsSpan));
if (ttsSpan == null) {
return;
}
Log.w("TESTING::ReactAccessibilityDelegate", "node.getText(): " + (node.getText()));
if (mView instanceof TextView) {
TextView textView = (TextView) mView;
Log.w("TESTING::ReactAccessibilityDelegate", "textView.getText(): " + (textView.getText()));
SpannableString spannableString = new SpannableString(textView.getText());
spannableString.setSpan(ttsSpan.span, 0, java.lang.Math.min(6, ttsSpan.end), 0);
CharSequence textViewText = ((TextView) mView).getText();
SpannableString spannableString = new SpannableString(textViewText);
spannableString.setSpan(
ttsSpan.span,
java.lang.Math.min(textViewText.length(), ttsSpan.start),
java.lang.Math.max(ttsSpan.start, ttsSpan.end - 1),
0);
node.setContentDescription(spannableString);
// node.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK);
// node.setRoleDescription(mView.getResources().getString(R.string.link_description));
// node.setHeading(true);
// node.setRoleDescription("heading");
// node.setClassName(AccessibilityRole.getValue(AccessibilityRole.BUTTON));
}
// String string = "my test string";
Log.w("TESTING::ReactAccessibilityDelegate", "ttsSpan.span: " + (ttsSpan.span));
Log.w("TESTING::ReactAccessibilityDelegate", "ttsSpan.end: " + (ttsSpan.end));
Log.w(
"TESTING::ReactAccessibilityDelegate",
"ttsSpan.span.getArgs(): " + (ttsSpan.span.getArgs()));
// TtsSpan ttsSpan = new TtsSpan.Builder(TtsSpan.TYPE_VERBATIM).build();

}
}

private Rect getBoundsInParent(AccessibilityLinks.AccessibleLink accessibleLink) {
Expand Down Expand Up @@ -700,6 +686,7 @@ public AccessibilityLinks(ReactTtsSpan[] spans, Spannable text) {
final AccessibleLink link = new AccessibleLink();
link.span = span;
link.start = start;
link.description = text.subSequence(start, end).toString();
link.end = end;

// ID is the reverse of what is expected, since the ClickableSpans are returned in reverse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.text.StaticLayout;
import android.text.TextPaint;
import android.util.LayoutDirection;
import android.util.Log;
import android.util.LruCache;
import android.view.View;
import androidx.annotation.NonNull;
Expand Down Expand Up @@ -156,9 +155,6 @@ private static void buildSpannableFromFragment(
start, end, new ReactBackgroundColorSpan(textAttributes.mBackgroundColor)));
*/
if (Build.VERSION.SDK_INT > 21 && textAttributes.mBackgroundColor == -65536) {
Log.w(
"TESTING::TextLayoutManagerMapBuffer",
"textAttributes.mBackgroundColor: " + (textAttributes.mBackgroundColor));
ops.add(
new SetSpanOperation(
start, end, new ReactTtsSpan.Builder(ReactTtsSpan.TYPE_VERBATIM).build()));
Expand Down

0 comments on commit 48a01d0

Please sign in to comment.