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 `<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 https://github.com/facebook/react-native/pull/7119 Differential Revision: D3240607 Pulled By: mkonicek fb-gh-sync-id: b13221ae1586594890b0f4aa644ace7c0d5d6c58 fbshipit-source-id: b13221ae1586594890b0f4aa644ace7c0d5d6c58
This commit is contained in:
parent
5e5cbda682
commit
3f0207d7b5
|
@ -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"));
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue