From 17a62b72b76124d84766736960ca9bc7350417d8 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Fri, 28 Feb 2020 22:40:14 -0800 Subject: [PATCH] Serialize and de-serialize text attachments for Android Summary: This diff implements serialization and deserialization of text attachments as part of the calculation of layout of text components changelog: [internal] Reviewed By: JoshuaGross Differential Revision: D20087251 fbshipit-source-id: dbcbd22f856aadace14343205548154ea80c8464 --- .../facebook/react/uimanager/ViewProps.java | 2 ++ .../react/views/text/TextAttributeProps.java | 18 ++++++++++++++++++ .../fabric/attributedstring/conversions.h | 5 +++++ 3 files changed, 25 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java index 5d08fbc181e..19926020b8a 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java @@ -62,6 +62,8 @@ public class ViewProps { public static final String START = "start"; public static final String END = "end"; + public static final String IS_ATTACHMENT = "isAttachment"; + public static final String AUTO = "auto"; public static final String NONE = "none"; public static final String BOX_NONE = "box-none"; diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextAttributeProps.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextAttributeProps.java index 9a829a75766..f6f5a6f1d1c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextAttributeProps.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextAttributeProps.java @@ -35,6 +35,9 @@ public class TextAttributeProps { private static final int DEFAULT_TEXT_SHADOW_COLOR = 0x55000000; + protected boolean mIsAttachment = false; + protected float mAttachmentWidth; + protected float mAttachmentHeight; protected float mLineHeight = Float.NaN; protected boolean mIsColorSet = false; protected boolean mAllowFontScaling = true; @@ -126,6 +129,21 @@ public class TextAttributeProps { setTextShadowRadius(getIntProp(PROP_SHADOW_RADIUS, 1)); setTextShadowColor(getIntProp(PROP_SHADOW_COLOR, DEFAULT_TEXT_SHADOW_COLOR)); setTextTransform(getStringProp(PROP_TEXT_TRANSFORM)); + setAttachmentHeight(getFloatProp(ViewProps.HEIGHT, UNSET)); + setAttachmentWidth(getFloatProp(ViewProps.WIDTH, UNSET)); + setIsAttachment(getBooleanProp(ViewProps.IS_ATTACHMENT, false)); + } + + private void setIsAttachment(boolean isAttachment) { + mIsAttachment = isAttachment; + } + + private void setAttachmentWidth(float attachmentWidth) { + mAttachmentWidth = attachmentWidth; + } + + private void setAttachmentHeight(float attachmentHeight) { + mAttachmentHeight = attachmentHeight; } private boolean getBooleanProp(String name, boolean defaultValue) { diff --git a/ReactCommon/fabric/attributedstring/conversions.h b/ReactCommon/fabric/attributedstring/conversions.h index fe0e99cd5cd..e52517bbbdf 100644 --- a/ReactCommon/fabric/attributedstring/conversions.h +++ b/ReactCommon/fabric/attributedstring/conversions.h @@ -580,6 +580,11 @@ inline folly::dynamic toDynamic(const AttributedString &attributedString) { if (fragment.parentShadowView.componentHandle) { dynamicFragment["reactTag"] = fragment.parentShadowView.tag; } + if (fragment.isAttachment()) { + dynamicFragment["isAttachment"] = true; + dynamicFragment["width"] = (int) fragment.parentShadowView.layoutMetrics.frame.size.width; + dynamicFragment["height"] = (int) fragment.parentShadowView.layoutMetrics.frame.size.height; + } dynamicFragment["textAttributes"] = toDynamic(fragment.textAttributes); fragments.push_back(dynamicFragment); }