Skip to content

Commit 99a9d26

Browse files
committed
EffectiveTextAttributeProvider: Use Kotlin-style getters
1 parent a6af5f2 commit 99a9d26

File tree

3 files changed

+106
-88
lines changed

3 files changed

+106
-88
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
}

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object TextLayoutUtils {
5656
fun addText(
5757
sb: SpannableStringBuilder, text: String?, textAttributeProvider: EffectiveTextAttributeProvider
5858
) {
59-
sb.append(TextTransform.apply(text, textAttributeProvider.getTextTransform()))
59+
sb.append(TextTransform.apply(text, textAttributeProvider.textTransform))
6060
}
6161

6262
fun addInlineViewPlaceholderSpan(
@@ -114,8 +114,8 @@ object TextLayoutUtils {
114114
end: Int
115115
) {
116116
val roleIsLink =
117-
textAttributeProvider.getRole()?.let { it == ReactAccessibilityDelegate.Role.LINK }
118-
?: (textAttributeProvider.getAccessibilityRole() == ReactAccessibilityDelegate.AccessibilityRole.LINK)
117+
textAttributeProvider.role?.let { it == ReactAccessibilityDelegate.Role.LINK }
118+
?: (textAttributeProvider.accessibilityRole == ReactAccessibilityDelegate.AccessibilityRole.LINK)
119119
if (roleIsLink) {
120120
ops.add(SetSpanOperation(start, end, ReactClickableSpan(reactTag)))
121121
}
@@ -127,10 +127,10 @@ object TextLayoutUtils {
127127
start: Int,
128128
end: Int
129129
) {
130-
if (textAttributeProvider.isColorSet()) {
130+
if (textAttributeProvider.isColorSet) {
131131
ops.add(
132132
SetSpanOperation(
133-
start, end, ReactForegroundColorSpan(textAttributeProvider.getColor())
133+
start, end, ReactForegroundColorSpan(textAttributeProvider.color)
134134
)
135135
)
136136
}
@@ -142,10 +142,10 @@ object TextLayoutUtils {
142142
start: Int,
143143
end: Int
144144
) {
145-
if (textAttributeProvider.isBackgroundColorSet()) {
145+
if (textAttributeProvider.isBackgroundColorSet) {
146146
ops.add(
147147
SetSpanOperation(
148-
start, end, ReactBackgroundColorSpan(textAttributeProvider.getBackgroundColor())
148+
start, end, ReactBackgroundColorSpan(textAttributeProvider.backgroundColor)
149149
)
150150
)
151151
}
@@ -157,7 +157,7 @@ object TextLayoutUtils {
157157
start: Int,
158158
end: Int
159159
) {
160-
val effectiveLetterSpacing = textAttributeProvider.getEffectiveLetterSpacing()
160+
val effectiveLetterSpacing = textAttributeProvider.effectiveLetterSpacing
161161

162162
if (!effectiveLetterSpacing.isNaN()) {
163163
ops.add(SetSpanOperation(start, end, CustomLetterSpacingSpan(effectiveLetterSpacing)))
@@ -170,7 +170,7 @@ object TextLayoutUtils {
170170
start: Int,
171171
end: Int
172172
) {
173-
val effectiveFontSize = textAttributeProvider.getEffectiveFontSize()
173+
val effectiveFontSize = textAttributeProvider.effectiveFontSize
174174

175175
if (effectiveFontSize != UNSET) {
176176
ops.add(SetSpanOperation(start, end, ReactAbsoluteSizeSpan(effectiveFontSize)))
@@ -184,17 +184,17 @@ object TextLayoutUtils {
184184
start: Int,
185185
end: Int
186186
) {
187-
val fontStyle = textAttributeProvider.getFontStyle()
188-
val fontWeight = textAttributeProvider.getFontWeight()
189-
val fontFamily = textAttributeProvider.getFontFamily()
187+
val fontStyle = textAttributeProvider.fontStyle
188+
val fontWeight = textAttributeProvider.fontWeight
189+
val fontFamily = textAttributeProvider.fontFamily
190190

191191
if (fontStyle != UNSET || fontWeight != UNSET || fontFamily != null) {
192192
ops.add(
193193
SetSpanOperation(
194194
start, end, CustomStyleSpan(
195195
fontStyle,
196196
fontWeight,
197-
textAttributeProvider.getFontFeatureSettings(),
197+
textAttributeProvider.fontFeatureSettings,
198198
fontFamily,
199199
context.assets
200200
)
@@ -209,7 +209,7 @@ object TextLayoutUtils {
209209
start: Int,
210210
end: Int
211211
) {
212-
if (textAttributeProvider.isUnderlineTextDecorationSet()) {
212+
if (textAttributeProvider.isUnderlineTextDecorationSet) {
213213
ops.add(SetSpanOperation(start, end, ReactUnderlineSpan()))
214214
}
215215
}
@@ -220,7 +220,7 @@ object TextLayoutUtils {
220220
start: Int,
221221
end: Int
222222
) {
223-
if (textAttributeProvider.isLineThroughTextDecorationSet()) {
223+
if (textAttributeProvider.isLineThroughTextDecorationSet) {
224224
ops.add(SetSpanOperation(start, end, ReactStrikethroughSpan()))
225225
}
226226
}
@@ -232,18 +232,18 @@ object TextLayoutUtils {
232232
end: Int
233233
) {
234234
val hasTextShadowOffset =
235-
textAttributeProvider.getTextShadowOffsetDx() != 0f || textAttributeProvider.getTextShadowOffsetDy() != 0f
236-
val hasTextShadowRadius = textAttributeProvider.getTextShadowRadius() != 0f
237-
val hasTextShadowColorAlpha = Color.alpha(textAttributeProvider.getTextShadowColor()) != 0
235+
textAttributeProvider.textShadowOffsetDx != 0f || textAttributeProvider.textShadowOffsetDy != 0f
236+
val hasTextShadowRadius = textAttributeProvider.textShadowRadius != 0f
237+
val hasTextShadowColorAlpha = Color.alpha(textAttributeProvider.textShadowColor) != 0
238238

239239
if ((hasTextShadowOffset || hasTextShadowRadius) && hasTextShadowColorAlpha) {
240240
ops.add(
241241
SetSpanOperation(
242242
start, end, ShadowStyleSpan(
243-
textAttributeProvider.getTextShadowOffsetDx(),
244-
textAttributeProvider.getTextShadowOffsetDy(),
245-
textAttributeProvider.getTextShadowRadius(),
246-
textAttributeProvider.getTextShadowColor()
243+
textAttributeProvider.textShadowOffsetDx,
244+
textAttributeProvider.textShadowOffsetDy,
245+
textAttributeProvider.textShadowRadius,
246+
textAttributeProvider.textShadowColor
247247
)
248248
)
249249
)
@@ -256,7 +256,7 @@ object TextLayoutUtils {
256256
start: Int,
257257
end: Int
258258
) {
259-
val effectiveLineHeight = textAttributeProvider.getEffectiveLineHeight()
259+
val effectiveLineHeight = textAttributeProvider.effectiveLineHeight
260260
if (!effectiveLineHeight.isNaN()) {
261261
ops.add(SetSpanOperation(start, end, CustomLineHeightSpan(effectiveLineHeight)))
262262
}

0 commit comments

Comments
 (0)