Skip to content

Commit 3f0207d

Browse files
KudoFacebook Github Bot 0
authored andcommitted
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](#4975 (comment)) **Test plan (required)** *Before this fix* 1. Modify TextExample.android.js to `<Text style={{fontSize: 20, textShadowOffset: {height: 10}, textShadowRadius: 1, textShadowColor: '#00cccc'}}>` which really raise a redbox. *After this fix* 1. Test original TextExample.android.js textShadowOffset works well. 2. Modify TextExample.android.js to `<Text style={{fontSize: 20, textShadowOffset: {height: 10}, textShadowRadius: 1, textShadowColor: '#00cccc'}}>` which works well without redbox. Closes #7119 Differential Revision: D3240607 Pulled By: mkonicek fb-gh-sync-id: b13221ae1586594890b0f4aa644ace7c0d5d6c58 fbshipit-source-id: b13221ae1586594890b0f4aa644ace7c0d5d6c58
1 parent 5e5cbda commit 3f0207d

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ public class ReactTextShadowNode extends LayoutShadowNode {
6767
public static final String PROP_TEXT = "text";
6868

6969
public static final String PROP_SHADOW_OFFSET = "textShadowOffset";
70+
public static final String PROP_SHADOW_OFFSET_WIDTH = "width";
71+
public static final String PROP_SHADOW_OFFSET_HEIGHT = "height";
7072
public static final String PROP_SHADOW_RADIUS = "textShadowRadius";
7173
public static final String PROP_SHADOW_COLOR = "textShadowColor";
74+
7275
public static final int DEFAULT_TEXT_SHADOW_COLOR = 0x55000000;
7376

7477
private static final TextPaint sTextPaintInstance = new TextPaint();
@@ -474,13 +477,22 @@ public void setTextDecorationLine(@Nullable String textDecorationLineString) {
474477

475478
@ReactProp(name = PROP_SHADOW_OFFSET)
476479
public void setTextShadowOffset(ReadableMap offsetMap) {
477-
if (offsetMap == null) {
478-
mTextShadowOffsetDx = 0;
479-
mTextShadowOffsetDy = 0;
480-
} else {
481-
mTextShadowOffsetDx = PixelUtil.toPixelFromDIP(offsetMap.getDouble("width"));
482-
mTextShadowOffsetDy = PixelUtil.toPixelFromDIP(offsetMap.getDouble("height"));
480+
mTextShadowOffsetDx = 0;
481+
mTextShadowOffsetDy = 0;
482+
483+
if (offsetMap != null) {
484+
if (offsetMap.hasKey(PROP_SHADOW_OFFSET_WIDTH) &&
485+
!offsetMap.isNull(PROP_SHADOW_OFFSET_WIDTH)) {
486+
mTextShadowOffsetDx =
487+
PixelUtil.toPixelFromDIP(offsetMap.getDouble(PROP_SHADOW_OFFSET_WIDTH));
488+
}
489+
if (offsetMap.hasKey(PROP_SHADOW_OFFSET_HEIGHT) &&
490+
!offsetMap.isNull(PROP_SHADOW_OFFSET_HEIGHT)) {
491+
mTextShadowOffsetDy =
492+
PixelUtil.toPixelFromDIP(offsetMap.getDouble(PROP_SHADOW_OFFSET_HEIGHT));
493+
}
483494
}
495+
484496
markUpdated();
485497
}
486498

0 commit comments

Comments
 (0)