[fix] set textShadow if only blur and color provided

Mirrors a recent fix to React Native.

Close #1182
This commit is contained in:
Hiroki Sato
2018-11-19 15:16:10 +09:00
committed by Nicolas Gallagher
parent 7663adebe8
commit d880457f22
2 changed files with 7 additions and 3 deletions

View File

@@ -284,7 +284,10 @@ describe('StyleSheet/createReactDOMStyle', () => {
});
test('textShadowColor and textShadowRadius only', () => {
expect(createReactDOMStyle({ textShadowColor: 'red', textShadowRadius: 5 })).toEqual({});
expect(createReactDOMStyle({ textShadowColor: 'red', textShadowRadius: 0 })).toEqual({});
expect(createReactDOMStyle({ textShadowColor: 'red', textShadowRadius: 5 })).toEqual({
textShadow: '0px 0px 5px rgba(255,0,0,1.00)'
});
});
test('textShadowColor, textShadowOffset, textShadowRadius', () => {

View File

@@ -117,12 +117,13 @@ const resolveTextDecoration = (resolvedStyle, style) => {
const resolveTextShadow = (resolvedStyle, style) => {
const { textShadowColor, textShadowOffset, textShadowRadius } = style;
const { height, width } = textShadowOffset || defaultOffset;
const radius = textShadowRadius || 0;
const offsetX = normalizeValue(null, width);
const offsetY = normalizeValue(null, height);
const blurRadius = normalizeValue(null, textShadowRadius || 0);
const blurRadius = normalizeValue(null, radius);
const color = normalizeColor(textShadowColor);
if (color && (height !== 0 || width !== 0)) {
if (color && (height !== 0 || width !== 0 || radius !== 0)) {
resolvedStyle.textShadow = `${offsetX} ${offsetY} ${blurRadius} ${color}`;
}
};