From 3f0207d7b5f55d28afa9a9f269d95e56904ea574 Mon Sep 17 00:00:00 2001 From: Kudo Chien Date: Fri, 29 Apr 2016 03:49:46 -0700 Subject: [PATCH] Fix textShadowOffset error without width or height Summary: textShadowOffset design is `ReactPropTypes.shape({width: ReactPropTypes.number, height: ReactPropTypes.number})`, so either width or height is optional. Unfortunately, in Android implementation, it is my bad not handling optional case and lead to an exception. Thanks kohver for reporting [this issue](https://github.com/facebook/react-native/pull/4975#issuecomment-213006641) **Test plan (required)** *Before this fix* 1. Modify TextExample.android.js to `` which really raise a redbox. *After this fix* 1. Test original TextExample.android.js textShadowOffset works well. 2. Modify TextExample.android.js to `` which works well without redbox. Closes https://github.com/facebook/react-native/pull/7119 Differential Revision: D3240607 Pulled By: mkonicek fb-gh-sync-id: b13221ae1586594890b0f4aa644ace7c0d5d6c58 fbshipit-source-id: b13221ae1586594890b0f4aa644ace7c0d5d6c58 --- .../react/views/text/ReactTextShadowNode.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java index b8a4811dc..a47fa7669 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java @@ -67,8 +67,11 @@ public class ReactTextShadowNode extends LayoutShadowNode { public static final String PROP_TEXT = "text"; public static final String PROP_SHADOW_OFFSET = "textShadowOffset"; + public static final String PROP_SHADOW_OFFSET_WIDTH = "width"; + public static final String PROP_SHADOW_OFFSET_HEIGHT = "height"; public static final String PROP_SHADOW_RADIUS = "textShadowRadius"; public static final String PROP_SHADOW_COLOR = "textShadowColor"; + public static final int DEFAULT_TEXT_SHADOW_COLOR = 0x55000000; private static final TextPaint sTextPaintInstance = new TextPaint(); @@ -474,13 +477,22 @@ public class ReactTextShadowNode extends LayoutShadowNode { @ReactProp(name = PROP_SHADOW_OFFSET) public void setTextShadowOffset(ReadableMap offsetMap) { - if (offsetMap == null) { - mTextShadowOffsetDx = 0; - mTextShadowOffsetDy = 0; - } else { - mTextShadowOffsetDx = PixelUtil.toPixelFromDIP(offsetMap.getDouble("width")); - mTextShadowOffsetDy = PixelUtil.toPixelFromDIP(offsetMap.getDouble("height")); + mTextShadowOffsetDx = 0; + mTextShadowOffsetDy = 0; + + if (offsetMap != null) { + if (offsetMap.hasKey(PROP_SHADOW_OFFSET_WIDTH) && + !offsetMap.isNull(PROP_SHADOW_OFFSET_WIDTH)) { + mTextShadowOffsetDx = + PixelUtil.toPixelFromDIP(offsetMap.getDouble(PROP_SHADOW_OFFSET_WIDTH)); + } + if (offsetMap.hasKey(PROP_SHADOW_OFFSET_HEIGHT) && + !offsetMap.isNull(PROP_SHADOW_OFFSET_HEIGHT)) { + mTextShadowOffsetDy = + PixelUtil.toPixelFromDIP(offsetMap.getDouble(PROP_SHADOW_OFFSET_HEIGHT)); + } } + markUpdated(); }