From 95a5d1c6287c7301265207d1962ba8b50d178b20 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Fri, 18 Oct 2024 03:29:34 -0700 Subject: [PATCH] Explicity reset typeface in updateTextPaint (#47097) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47097 Calling Paint.reset() doesn't reset the active type face (https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/libs/hwui/hwui/PaintImpl.cpp;l=86), which causes measurements bugs for Text which don't specify a font to be incorrect. Changelog: [Android][Fixed] Text without explicit font styles was potentially cut-off. Reviewed By: NickGerleman Differential Revision: D64535719 fbshipit-source-id: d300c26bf828a0e2e4b170254f9be5f409aff2dc --- .../com/facebook/react/views/text/TextLayoutManager.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java index 6e22ae9f409..63bb805fcac 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java @@ -432,10 +432,11 @@ public class TextLayoutManager { private static void updateTextPaint( TextPaint paint, TextAttributeProps baseTextAttributes, Context context) { // TextPaint attributes will be used for content outside the Spannable, like for the - // hypothetical height of a new line after a trailing newline charater (considered part of the + // hypothetical height of a new line after a trailing newline character (considered part of the // previous line). paint.reset(); paint.setAntiAlias(true); + if (baseTextAttributes.getEffectiveFontSize() != ReactConstants.UNSET) { paint.setTextSize(baseTextAttributes.getEffectiveFontSize()); } @@ -459,6 +460,8 @@ public class TextLayoutManager { paint.setFakeBoldText((missingStyle & Typeface.BOLD) != 0); paint.setTextSkewX((missingStyle & Typeface.ITALIC) != 0 ? -0.25f : 0); } + } else { + paint.setTypeface(null); } }