From 561a97f699dc7551c88facdb0efeb9550e037594 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Thu, 7 May 2020 17:08:17 -0700 Subject: [PATCH] Extend Text measurement to support includeFontPadding prop Summary: This diff exposes the Text.includeFontPadding prop to java, then it uses the prop to calculate the height of Text components correctly. changelog: [Internal][Fabric] Internal change in Fabric to support Text.includeFontPadding prop in fabric Reviewed By: shergin Differential Revision: D21446737 fbshipit-source-id: efe73fb6b0d402c3275ac8c012fa8fa06b743bdd --- .../com/facebook/react/views/text/TextLayoutManager.java | 6 +++++- ReactCommon/fabric/attributedstring/conversions.h | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java index 4b64720d80e..76176981b55 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java @@ -46,6 +46,7 @@ public class TextLayoutManager { private static final String INLINE_VIEW_PLACEHOLDER = "0"; private static final Object sSpannableCacheLock = new Object(); + private static final boolean DEFAULT_INCLUDE_FONT_PADDING = true; private static LruCache sSpannableCache = new LruCache<>(spannableCacheSize); public static boolean isRTL(ReadableMap attributedString) { @@ -221,7 +222,10 @@ public class TextLayoutManager { int textBreakStrategy = TextAttributeProps.getTextBreakStrategy(paragraphAttributes.getString("textBreakStrategy")); - boolean includeFontPadding = true; + boolean includeFontPadding = + paragraphAttributes.hasKey("includeFontPadding") + ? paragraphAttributes.getBoolean("includeFontPadding") + : DEFAULT_INCLUDE_FONT_PADDING; if (preparedSpannableText == null) { throw new IllegalStateException("Spannable element has not been prepared in onBeforeLayout"); diff --git a/ReactCommon/fabric/attributedstring/conversions.h b/ReactCommon/fabric/attributedstring/conversions.h index e92f06ace4b..774913dcd32 100644 --- a/ReactCommon/fabric/attributedstring/conversions.h +++ b/ReactCommon/fabric/attributedstring/conversions.h @@ -448,6 +448,11 @@ inline ParagraphAttributes convertRawProp( "maximumFontSize", sourceParagraphAttributes.maximumFontSize, defaultParagraphAttributes.maximumFontSize); + paragraphAttributes.includeFontPadding = convertRawProp( + rawProps, + "includeFontPadding", + sourceParagraphAttributes.includeFontPadding, + defaultParagraphAttributes.includeFontPadding); return paragraphAttributes; } @@ -481,6 +486,8 @@ inline folly::dynamic toDynamic( values("ellipsizeMode", toString(paragraphAttributes.ellipsizeMode)); values("textBreakStrategy", toString(paragraphAttributes.textBreakStrategy)); values("adjustsFontSizeToFit", paragraphAttributes.adjustsFontSizeToFit); + values("includeFontPadding", paragraphAttributes.includeFontPadding); + return values; }