Skip to content

Commit d905a71

Browse files
committed
test: call text paint update directly
1 parent e71870f commit d905a71

2 files changed

Lines changed: 5 additions & 25 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ internal object TextLayoutManager {
859859
* Sets attributes on the TextPaint, used for content outside the Spannable text, like for empty
860860
* strings, or newlines after the last trailing character
861861
*/
862-
private fun updateTextPaint(
862+
internal fun updateTextPaint(
863863
paint: TextPaint,
864864
baseTextAttributes: TextAttributeProps,
865865
assets: AssetManager,

packages/react-native/ReactAndroid/src/test/java/com/facebook/react/views/text/TextLayoutManagerFontWeightAdjustmentTest.kt

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
package com.facebook.react.views.text
99

10-
import android.content.res.AssetManager
1110
import android.graphics.Typeface
1211
import android.text.SpannableString
1312
import android.text.TextPaint
1413
import com.facebook.react.bridge.JavaOnlyMap
14+
import com.facebook.react.common.annotations.UnstableReactNativeAPI
1515
import com.facebook.react.common.mapbuffer.WritableMapBuffer
1616
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags
1717
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsForTests
@@ -30,6 +30,7 @@ import org.robolectric.annotation.Config
3030

3131
@RunWith(RobolectricTestRunner::class)
3232
@Config(sdk = [34])
33+
@OptIn(UnstableReactNativeAPI::class)
3334
class TextLayoutManagerFontWeightAdjustmentTest {
3435

3536
@Before
@@ -50,7 +51,7 @@ class TextLayoutManagerFontWeightAdjustmentTest {
5051
val paint = TextPaint(TextPaint.ANTI_ALIAS_FLAG)
5152
val textAttributes = TextAttributeProps.fromReadableMap(ReactStylesDiffMap(JavaOnlyMap()))
5253

53-
invokeUpdateTextPaint(
54+
TextLayoutManager.updateTextPaint(
5455
paint,
5556
textAttributes,
5657
RuntimeEnvironment.getApplication().assets,
@@ -66,7 +67,7 @@ class TextLayoutManagerFontWeightAdjustmentTest {
6667
val paint = TextPaint(TextPaint.ANTI_ALIAS_FLAG)
6768
val textAttributes = TextAttributeProps.fromReadableMap(ReactStylesDiffMap(JavaOnlyMap()))
6869

69-
invokeUpdateTextPaint(
70+
TextLayoutManager.updateTextPaint(
7071
paint,
7172
textAttributes,
7273
RuntimeEnvironment.getApplication().assets,
@@ -120,27 +121,6 @@ class TextLayoutManagerFontWeightAdjustmentTest {
120121
assertThat(recachedSpannable).isSameAs(adjustedSpannable)
121122
}
122123

123-
private fun invokeUpdateTextPaint(
124-
paint: TextPaint,
125-
textAttributes: TextAttributeProps,
126-
assets: AssetManager,
127-
fontWeightAdjustment: Int,
128-
) {
129-
val method =
130-
TextLayoutManager::class
131-
.java
132-
.getDeclaredMethod(
133-
"updateTextPaint",
134-
TextPaint::class.java,
135-
TextAttributeProps::class.java,
136-
AssetManager::class.java,
137-
java.lang.Integer.TYPE,
138-
)
139-
.apply { isAccessible = true }
140-
141-
method.invoke(TextLayoutManager, paint, textAttributes, assets, fontWeightAdjustment)
142-
}
143-
144124
private companion object {
145125
const val CACHE_ID = 1001
146126
const val FONT_WEIGHT_ADJUSTMENT_BOLD_TEXT = 300

0 commit comments

Comments
 (0)