Skip to content

Commit 6cceac3

Browse files
committed
HierarchicTextAttributeProvider: Delegate most properties to the node itself
1 parent 8b95108 commit 6cceac3

File tree

4 files changed

+61
-86
lines changed

4 files changed

+61
-86
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.facebook.react.internal.views.text
2+
3+
import com.facebook.react.uimanager.ReactAccessibilityDelegate
4+
5+
/**
6+
* Interface for an entity providing basic text attributes of a text node/fragment. "Basic" means
7+
* that they can be provided trivially, without processing the parent element.
8+
*/
9+
interface BasicTextAttributeProvider {
10+
val role: ReactAccessibilityDelegate.Role?
11+
12+
val accessibilityRole: ReactAccessibilityDelegate.AccessibilityRole?
13+
14+
val isBackgroundColorSet: Boolean
15+
16+
val backgroundColor: Int
17+
18+
val isColorSet: Boolean
19+
20+
val color: Int
21+
22+
val fontStyle: Int
23+
24+
val fontWeight: Int
25+
26+
val fontFamily: String?
27+
28+
val fontFeatureSettings: String?
29+
30+
val isUnderlineTextDecorationSet: Boolean
31+
32+
val isLineThroughTextDecorationSet: Boolean
33+
34+
val textShadowOffsetDx: Float
35+
36+
val textShadowOffsetDy: Float
37+
38+
val textShadowRadius: Float
39+
40+
val textShadowColor: Int
41+
}
Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package com.facebook.react.internal.views.text
22

33
import com.facebook.react.common.assets.ReactFontManager
4-
import com.facebook.react.uimanager.ReactAccessibilityDelegate
5-
import com.facebook.react.uimanager.ReactAccessibilityDelegate.Role
64
import com.facebook.react.views.text.TextTransform
75

86
/**
97
* Interface for an entity providing effective text attributes of a text node/fragment
108
*/
11-
interface EffectiveTextAttributeProvider {
9+
interface EffectiveTextAttributeProvider : BasicTextAttributeProvider {
1210
companion object {
1311
const val UNSET = ReactFontManager.TypefaceStyle.UNSET
1412
}
@@ -22,37 +20,5 @@ interface EffectiveTextAttributeProvider {
2220
*/
2321
val effectiveFontSize: Int
2422

25-
val role: Role?
26-
27-
val accessibilityRole: ReactAccessibilityDelegate.AccessibilityRole?
28-
29-
val isBackgroundColorSet: Boolean
30-
31-
val backgroundColor: Int
32-
33-
val isColorSet: Boolean
34-
35-
val color: Int
36-
37-
val fontStyle: Int
38-
39-
val fontWeight: Int
40-
41-
val fontFamily: String?
42-
43-
val fontFeatureSettings: String?
44-
45-
val isUnderlineTextDecorationSet: Boolean
46-
47-
val isLineThroughTextDecorationSet: Boolean
48-
49-
val textShadowOffsetDx: Float
50-
51-
val textShadowOffsetDy: Float
52-
53-
val textShadowRadius: Float
54-
55-
val textShadowColor: Int
56-
5723
val effectiveLineHeight: Float
5824
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/views/text/HierarchicTextAttributeProvider.kt

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.facebook.react.internal.views.text
22

3-
import com.facebook.react.uimanager.ReactAccessibilityDelegate
43
import com.facebook.react.views.text.ReactBaseTextShadowNode
54
import com.facebook.react.views.text.TextAttributes
65
import com.facebook.react.views.text.TextTransform
@@ -13,58 +12,10 @@ class HierarchicTextAttributeProvider(
1312
private val textShadowNode: ReactBaseTextShadowNode,
1413
private val parentTextAttributes: TextAttributes?,
1514
private val textAttributes: TextAttributes
16-
) : EffectiveTextAttributeProvider {
15+
) : EffectiveTextAttributeProvider, BasicTextAttributeProvider by textShadowNode {
1716
override val textTransform: TextTransform
1817
get() = textAttributes.textTransform
1918

20-
override val role: ReactAccessibilityDelegate.Role?
21-
get() = textShadowNode.role
22-
23-
override val accessibilityRole: ReactAccessibilityDelegate.AccessibilityRole?
24-
get() = textShadowNode.accessibilityRole
25-
26-
override val isBackgroundColorSet: Boolean
27-
get() = textShadowNode.isBackgroundColorSet
28-
29-
override val backgroundColor: Int
30-
get() = textShadowNode.backgroundColor
31-
32-
override val isColorSet: Boolean
33-
get() = textShadowNode.isColorSet
34-
35-
override val color: Int
36-
get() = textShadowNode.color
37-
38-
override val fontStyle: Int
39-
get() = textShadowNode.fontStyle
40-
41-
override val fontWeight: Int
42-
get() = textShadowNode.fontWeight
43-
44-
override val fontFamily: String
45-
get() = textShadowNode.fontFamily
46-
47-
override val fontFeatureSettings: String
48-
get() = textShadowNode.fontFeatureSettings
49-
50-
override val isUnderlineTextDecorationSet: Boolean
51-
get() = textShadowNode.isUnderlineTextDecorationSet
52-
53-
override val isLineThroughTextDecorationSet: Boolean
54-
get() = textShadowNode.isLineThroughTextDecorationSet
55-
56-
override val textShadowOffsetDx: Float
57-
get() = textShadowNode.textShadowOffsetDx
58-
59-
override val textShadowOffsetDy: Float
60-
get() = textShadowNode.textShadowOffsetDy
61-
62-
override val textShadowRadius: Float
63-
get() = textShadowNode.textShadowRadius
64-
65-
override val textShadowColor: Int
66-
get() = textShadowNode.textShadowColor
67-
6819
override val effectiveLetterSpacing: Float
6920
get() {
7021
val letterSpacing = textAttributes.effectiveLetterSpacing

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.facebook.react.bridge.ReadableMap;
2323
import com.facebook.react.common.ReactConstants;
2424
import com.facebook.react.common.assets.ReactFontManager;
25+
import com.facebook.react.internal.views.text.BasicTextAttributeProvider;
2526
import com.facebook.react.internal.views.text.HierarchicTextAttributeProvider;
2627
import com.facebook.react.internal.views.text.TextLayoutUtils;
2728
import com.facebook.react.uimanager.IllegalViewOperationException;
@@ -51,7 +52,7 @@
5152
* <p>This also node calculates {@link Spannable} object based on subnodes of the same type, which
5253
* can be used in concrete classes to feed native views and compute layout.
5354
*/
54-
public abstract class ReactBaseTextShadowNode extends LayoutShadowNode {
55+
public abstract class ReactBaseTextShadowNode extends LayoutShadowNode implements BasicTextAttributeProvider {
5556

5657
private static final TextLayoutUtils textLayoutUtils = TextLayoutUtils.INSTANCE;
5758

@@ -391,6 +392,7 @@ public void setFontSize(float fontSize) {
391392
markUpdated();
392393
}
393394

395+
@Override
394396
public int getColor() {
395397
return mColor;
396398
}
@@ -404,10 +406,12 @@ public void setColor(@Nullable Integer color) {
404406
markUpdated();
405407
}
406408

409+
@Override
407410
public boolean isColorSet() {
408411
return mIsColorSet;
409412
}
410413

414+
@Override
411415
public int getBackgroundColor() {
412416
return mBackgroundColor;
413417
}
@@ -427,10 +431,12 @@ public void setBackgroundColor(@Nullable Integer color) {
427431
}
428432
}
429433

434+
@Override
430435
public boolean isBackgroundColorSet() {
431436
return mIsBackgroundColorSet;
432437
}
433438

439+
@Override
434440
public @Nullable AccessibilityRole getAccessibilityRole() {
435441
return mAccessibilityRole;
436442
}
@@ -443,6 +449,7 @@ public void setAccessibilityRole(@Nullable String accessibilityRole) {
443449
}
444450
}
445451

452+
@Override
446453
public @Nullable Role getRole() {
447454
return mRole;
448455
}
@@ -455,6 +462,7 @@ public void setRole(@Nullable String role) {
455462
}
456463
}
457464

465+
@Override
458466
public String getFontFamily() {
459467
return mFontFamily;
460468
}
@@ -465,6 +473,7 @@ public void setFontFamily(@Nullable String fontFamily) {
465473
markUpdated();
466474
}
467475

476+
@Override
468477
public int getFontWeight() {
469478
return mFontWeight;
470479
}
@@ -488,10 +497,12 @@ public void setFontVariant(@Nullable ReadableArray fontVariantArray) {
488497
}
489498
}
490499

500+
@Override
491501
public String getFontFeatureSettings() {
492502
return mFontFeatureSettings;
493503
}
494504

505+
@Override
495506
public int getFontStyle() {
496507
return mFontStyle;
497508
}
@@ -526,10 +537,12 @@ public void setTextDecorationLine(@Nullable String textDecorationLineString) {
526537
markUpdated();
527538
}
528539

540+
@Override
529541
public boolean isUnderlineTextDecorationSet() {
530542
return mIsUnderlineTextDecorationSet;
531543
}
532544

545+
@Override
533546
public boolean isLineThroughTextDecorationSet() {
534547
return mIsLineThroughTextDecorationSet;
535548
}
@@ -571,14 +584,17 @@ public void setTextShadowOffset(ReadableMap offsetMap) {
571584
markUpdated();
572585
}
573586

587+
@Override
574588
public float getTextShadowOffsetDx() {
575589
return mTextShadowOffsetDx;
576590
}
577591

592+
@Override
578593
public float getTextShadowOffsetDy() {
579594
return mTextShadowOffsetDy;
580595
}
581596

597+
@Override
582598
public float getTextShadowRadius() {
583599
return mTextShadowRadius;
584600
}
@@ -591,6 +607,7 @@ public void setTextShadowRadius(float textShadowRadius) {
591607
}
592608
}
593609

610+
@Override
594611
public int getTextShadowColor() {
595612
return mTextShadowColor;
596613
}

0 commit comments

Comments
 (0)