Skip to content

Commit

Permalink
Fix textShadowOffset error without width or height
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Kudo authored and Facebook Github Bot 0 committed Apr 29, 2016
1 parent 5e5cbda commit 3f0207d
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -474,13 +477,22 @@ public void setTextDecorationLine(@Nullable String textDecorationLineString) {

@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();
}

Expand Down

0 comments on commit 3f0207d

Please sign in to comment.