Skip to content

Commit 8b95108

Browse files
committed
EffectiveTextAttributeProvider: Use Kotlin-style getters
1 parent 50a4fa5 commit 8b95108

File tree

2 files changed

+83
-65
lines changed

2 files changed

+83
-65
lines changed

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,46 @@ interface EffectiveTextAttributeProvider {
1313
const val UNSET = ReactFontManager.TypefaceStyle.UNSET
1414
}
1515

16-
fun getTextTransform(): TextTransform
16+
val textTransform: TextTransform
1717

18-
fun getEffectiveLetterSpacing(): Float
18+
val effectiveLetterSpacing: Float
1919

2020
/**
2121
* @return The effective font size, or {@link #UNSET} if not set
2222
*/
23-
fun getEffectiveFontSize(): Int
23+
val effectiveFontSize: Int
2424

25-
fun getRole(): Role?
25+
val role: Role?
2626

27-
fun getAccessibilityRole(): ReactAccessibilityDelegate.AccessibilityRole?
27+
val accessibilityRole: ReactAccessibilityDelegate.AccessibilityRole?
2828

29-
fun isBackgroundColorSet(): Boolean
29+
val isBackgroundColorSet: Boolean
3030

31-
fun getBackgroundColor(): Int
31+
val backgroundColor: Int
3232

33-
fun isColorSet(): Boolean
33+
val isColorSet: Boolean
3434

35-
fun getColor(): Int
35+
val color: Int
3636

37-
fun getFontStyle(): Int
37+
val fontStyle: Int
3838

39-
fun getFontWeight(): Int
39+
val fontWeight: Int
4040

41-
fun getFontFamily(): String?
41+
val fontFamily: String?
4242

43-
fun getFontFeatureSettings(): String?
43+
val fontFeatureSettings: String?
4444

45-
fun isUnderlineTextDecorationSet(): Boolean
45+
val isUnderlineTextDecorationSet: Boolean
4646

47-
fun isLineThroughTextDecorationSet(): Boolean
47+
val isLineThroughTextDecorationSet: Boolean
4848

49-
fun getTextShadowOffsetDx(): Float
49+
val textShadowOffsetDx: Float
5050

51-
fun getTextShadowOffsetDy(): Float
51+
val textShadowOffsetDy: Float
5252

53-
fun getTextShadowRadius(): Float
53+
val textShadowRadius: Float
5454

55-
fun getTextShadowColor(): Int
55+
val textShadowColor: Int
5656

57-
fun getEffectiveLineHeight(): Float
57+
val effectiveLineHeight: Float
5858
}

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

Lines changed: 63 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,74 +14,92 @@ class HierarchicTextAttributeProvider(
1414
private val parentTextAttributes: TextAttributes?,
1515
private val textAttributes: TextAttributes
1616
) : EffectiveTextAttributeProvider {
17-
override fun getTextTransform(): TextTransform = textAttributes.textTransform
17+
override val textTransform: TextTransform
18+
get() = textAttributes.textTransform
1819

19-
override fun getRole(): ReactAccessibilityDelegate.Role? = textShadowNode.role
20+
override val role: ReactAccessibilityDelegate.Role?
21+
get() = textShadowNode.role
2022

21-
override fun getAccessibilityRole(): ReactAccessibilityDelegate.AccessibilityRole? =
22-
textShadowNode.accessibilityRole
23+
override val accessibilityRole: ReactAccessibilityDelegate.AccessibilityRole?
24+
get() = textShadowNode.accessibilityRole
2325

24-
override fun isBackgroundColorSet(): Boolean = textShadowNode.isBackgroundColorSet
26+
override val isBackgroundColorSet: Boolean
27+
get() = textShadowNode.isBackgroundColorSet
2528

26-
override fun getBackgroundColor(): Int = textShadowNode.backgroundColor
29+
override val backgroundColor: Int
30+
get() = textShadowNode.backgroundColor
2731

28-
override fun isColorSet(): Boolean = textShadowNode.isColorSet
32+
override val isColorSet: Boolean
33+
get() = textShadowNode.isColorSet
2934

30-
override fun getColor(): Int = textShadowNode.color
35+
override val color: Int
36+
get() = textShadowNode.color
3137

32-
override fun getFontStyle(): Int = textShadowNode.fontStyle
38+
override val fontStyle: Int
39+
get() = textShadowNode.fontStyle
3340

34-
override fun getFontWeight(): Int = textShadowNode.fontWeight
41+
override val fontWeight: Int
42+
get() = textShadowNode.fontWeight
3543

36-
override fun getFontFamily(): String = textShadowNode.fontFamily
44+
override val fontFamily: String
45+
get() = textShadowNode.fontFamily
3746

38-
override fun getFontFeatureSettings(): String = textShadowNode.fontFeatureSettings
47+
override val fontFeatureSettings: String
48+
get() = textShadowNode.fontFeatureSettings
3949

40-
override fun isUnderlineTextDecorationSet(): Boolean = textShadowNode.isUnderlineTextDecorationSet
50+
override val isUnderlineTextDecorationSet: Boolean
51+
get() = textShadowNode.isUnderlineTextDecorationSet
4152

42-
override fun isLineThroughTextDecorationSet(): Boolean =
43-
textShadowNode.isLineThroughTextDecorationSet
53+
override val isLineThroughTextDecorationSet: Boolean
54+
get() = textShadowNode.isLineThroughTextDecorationSet
4455

45-
override fun getTextShadowOffsetDx(): Float = textShadowNode.textShadowOffsetDx
56+
override val textShadowOffsetDx: Float
57+
get() = textShadowNode.textShadowOffsetDx
4658

47-
override fun getTextShadowOffsetDy(): Float = textShadowNode.textShadowOffsetDy
59+
override val textShadowOffsetDy: Float
60+
get() = textShadowNode.textShadowOffsetDy
4861

49-
override fun getTextShadowRadius(): Float = textShadowNode.textShadowRadius
62+
override val textShadowRadius: Float
63+
get() = textShadowNode.textShadowRadius
5064

51-
override fun getTextShadowColor(): Int = textShadowNode.textShadowColor
65+
override val textShadowColor: Int
66+
get() = textShadowNode.textShadowColor
5267

53-
override fun getEffectiveLetterSpacing(): Float {
54-
val letterSpacing = textAttributes.effectiveLetterSpacing
68+
override val effectiveLetterSpacing: Float
69+
get() {
70+
val letterSpacing = textAttributes.effectiveLetterSpacing
5571

56-
val isParentLetterSpacingDifferent =
57-
parentTextAttributes == null || parentTextAttributes.effectiveLetterSpacing != letterSpacing
72+
val isParentLetterSpacingDifferent =
73+
parentTextAttributes == null || parentTextAttributes.effectiveLetterSpacing != letterSpacing
5874

59-
return if (!letterSpacing.isNaN() && isParentLetterSpacingDifferent) {
60-
letterSpacing
61-
} else {
62-
Float.NaN
75+
return if (!letterSpacing.isNaN() && isParentLetterSpacingDifferent) {
76+
letterSpacing
77+
} else {
78+
Float.NaN
79+
}
6380
}
64-
}
6581

66-
override fun getEffectiveFontSize(): Int {
67-
val fontSize = textAttributes.effectiveFontSize
82+
override val effectiveFontSize: Int
83+
get() {
84+
val fontSize = textAttributes.effectiveFontSize
6885

69-
return if (parentTextAttributes == null || parentTextAttributes.effectiveFontSize != fontSize) {
70-
fontSize
71-
} else {
72-
EffectiveTextAttributeProvider.UNSET
86+
return if (parentTextAttributes == null || parentTextAttributes.effectiveFontSize != fontSize) {
87+
fontSize
88+
} else {
89+
EffectiveTextAttributeProvider.UNSET
90+
}
7391
}
74-
}
7592

76-
override fun getEffectiveLineHeight(): Float {
77-
val lineHeight = textAttributes.effectiveLineHeight
78-
val isParentLineHeightDifferent =
79-
parentTextAttributes == null || parentTextAttributes.effectiveLineHeight != lineHeight
80-
81-
return if (!lineHeight.isNaN() && isParentLineHeightDifferent) {
82-
lineHeight
83-
} else {
84-
Float.NaN
93+
override val effectiveLineHeight: Float
94+
get() {
95+
val lineHeight = textAttributes.effectiveLineHeight
96+
val isParentLineHeightDifferent =
97+
parentTextAttributes == null || parentTextAttributes.effectiveLineHeight != lineHeight
98+
99+
return if (!lineHeight.isNaN() && isParentLineHeightDifferent) {
100+
lineHeight
101+
} else {
102+
Float.NaN
103+
}
85104
}
86-
}
87105
}

0 commit comments

Comments
 (0)