Skip to content

Commit e215baa

Browse files
committed
adding TtsSpan with type date
1 parent d845073 commit e215baa

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.List;
3737
import java.util.Map;
3838
import java.util.Objects;
39+
import java.util.Set;
3940

4041
/**
4142
* {@link ReactShadowNode} abstract class for spannable text nodes.
@@ -184,7 +185,9 @@ private static void buildSpannedFromShadowNode(
184185
new SetSpanOperation(start, end, new ReactClickableSpan(textShadowNode.getReactTag())));
185186
}
186187
if (textShadowNode.mIsAccessibilityUnit && Build.VERSION.SDK_INT >= 21) {
187-
ops.add(new SetSpanOperation(start, end, new ReactTtsSpan.Builder("verbatim").build()));
188+
ops.add(
189+
new SetSpanOperation(
190+
start, end, new ReactTtsSpan.Builder(textShadowNode.mAccessibilityRole).build()));
188191
}
189192
float effectiveLetterSpacing = textAttributes.getEffectiveLetterSpacing();
190193
if (!Float.isNaN(effectiveLetterSpacing)
@@ -327,6 +330,7 @@ protected Spannable spannedFromShadowNode(
327330
protected int mColor;
328331
protected boolean mIsBackgroundColorSet = false;
329332
protected int mBackgroundColor;
333+
protected String mAccessibilityRole;
330334
protected boolean mIsAccessibilityLink = false;
331335
protected boolean mIsAccessibilityUnit;
332336

@@ -503,8 +507,10 @@ public void setBackgroundColor(@Nullable Integer color) {
503507
@ReactProp(name = ViewProps.ACCESSIBILITY_ROLE)
504508
public void setIsAccessibilityLink(@Nullable String accessibilityRole) {
505509
if (isVirtual()) {
510+
mAccessibilityRole = accessibilityRole;
506511
mIsAccessibilityLink = Objects.equals(accessibilityRole, "link");
507-
mIsAccessibilityUnit = Objects.equals(accessibilityRole, "verbatim");
512+
Set<String> TYPES = Set.of("verbatim", "date");
513+
mIsAccessibilityUnit = TYPES.contains(accessibilityRole);
508514
markUpdated();
509515
}
510516
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public static class Builder<C extends Builder<?>> {
3030
public Builder(String type) {
3131
if (type == "verbatim") {
3232
mType = TYPE_VERBATIM;
33+
} else if (type == "date") {
34+
mType = TYPE_DATE;
3335
} else {
3436
mType = TYPE_TEXT;
3537
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,6 @@ private static void buildSpannableFromFragment(
148148
new SetSpanOperation(
149149
start, end, new ReactForegroundColorSpan(textAttributes.mColor)));
150150
}
151-
if (textAttributes.mIsAccessibilityUnit) {
152-
if (Build.VERSION.SDK_INT > 21) {
153-
ops.add(new SetSpanOperation(start, end, new ReactTtsSpan.Builder("verbatim").build()));
154-
}
155-
}
156151
if (textAttributes.mIsBackgroundColorSet) {
157152
ops.add(
158153
new SetSpanOperation(

packages/rn-tester/js/examples/Text/TextAdjustsDynamicLayoutExample.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function TextAdjustsDynamicLayoutExample(props: {}): React.Node {
2323
accessibilityRole="verbatim"
2424
accessible={true}
2525
style={{backgroundColor: 'red'}}>
26-
please spell this text
26+
02/07/1987
2727
</Text>
2828
.
2929
</Text>

0 commit comments

Comments
 (0)