From fd3e2135938e0530f4c594fcbff5eb62cac62402 Mon Sep 17 00:00:00 2001 From: Denis Koroskin Date: Wed, 23 Dec 2015 14:55:45 -0800 Subject: [PATCH] Update RCTText.PAINT's text size to ensure that ellipsis is measured correctly Summary: placeholder Reviewed By: ahmedre Differential Revision: D2786310 --- .../src/main/java/com/facebook/react/flat/RCTText.java | 6 ++++++ .../main/java/com/facebook/react/flat/RCTVirtualText.java | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTText.java b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTText.java index c30830bb1..b897b9cd8 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTText.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTText.java @@ -106,6 +106,12 @@ import com.facebook.react.uimanager.ViewProps; int maximumWidth = Float.isNaN(width) ? Integer.MAX_VALUE : (int) width; + // Make sure we update the paint's text size. If we don't do this, ellipsis might be measured + // incorrecly (but drawn correctly, which almost feels like an Android bug, because width of the + // created layout may exceed the requested width). This is safe to do without making a copy per + // RCTText instance because that size is ONLY used to measure the ellipsis but not to draw it. + PAINT.setTextSize(getFontSize()); + // at this point we need to create a StaticLayout to measure the text StaticLayout layout = StaticLayoutHelper.make( text, diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTVirtualText.java b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTVirtualText.java index b38e9e9dd..167d5a0d9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTVirtualText.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTVirtualText.java @@ -152,6 +152,14 @@ import com.facebook.react.uimanager.ViewProps; } } + /** + * Returns font size for this node. + * When called on RCTText, this value is never -1 (unset). + */ + protected final int getFontSize() { + return mFontStylingSpan.getFontSize(); + } + protected int getDefaultFontSize() { return -1; }