Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,74 +213,89 @@ describe('StyleSheet/preprocess', () => {
});

describe('preprocesses multiple shadow styles into a single declaration', () => {
const options = { shadow: true };

test('shadowColor only', () => {
expect(preprocess({ shadowColor: 'red' })).toEqual({
expect(preprocess({ shadowColor: 'red' }, options)).toEqual({
boxShadow: '0px 0px 0px rgba(255,0,0,1.00)'
});
});

test('shadowColor and shadowOpacity only', () => {
expect(preprocess({ shadowColor: 'red', shadowOpacity: 0.5 })).toEqual({
expect(
preprocess({ shadowColor: 'red', shadowOpacity: 0.5 }, options)
).toEqual({
boxShadow: '0px 0px 0px rgba(255,0,0,0.50)'
});
});

test('shadowOffset only', () => {
expect(preprocess({ shadowOffset: { width: 1, height: 2 } })).toEqual({
expect(
preprocess({ shadowOffset: { width: 1, height: 2 } }, options)
).toEqual({
boxShadow: '1px 2px 0px rgba(0,0,0,1.00)'
});
});

test('shadowRadius only', () => {
expect(preprocess({ shadowRadius: 5 })).toEqual({
expect(preprocess({ shadowRadius: 5 }, options)).toEqual({
boxShadow: '0px 0px 5px rgba(0,0,0,1.00)'
});
});

test('shadowOffset, shadowRadius, shadowColor', () => {
expect(
preprocess({
shadowColor: 'rgba(50,60,70,0.5)',
shadowOffset: { width: 1, height: 2 },
shadowOpacity: 0.5,
shadowRadius: 3
})
preprocess(
{
shadowColor: 'rgba(50,60,70,0.5)',
shadowOffset: { width: 1, height: 2 },
shadowOpacity: 0.5,
shadowRadius: 3
},
options
)
).toEqual({
boxShadow: '1px 2px 3px rgba(50,60,70,0.25)'
});
});

test('shadow styles and string boxShadow together', () => {
expect(
preprocess({
shadowColor: 'rgba(50,60,70,0.5)',
shadowOffset: { width: 1, height: 2 },
shadowOpacity: 0.5,
shadowRadius: 3,
boxShadow: '4px 5px 6px black'
})
preprocess(
{
shadowColor: 'rgba(50,60,70,0.5)',
shadowOffset: { width: 1, height: 2 },
shadowOpacity: 0.5,
shadowRadius: 3,
boxShadow: '4px 5px 6px black'
},
options
)
).toEqual({
boxShadow: '4px 5px 6px black, 1px 2px 3px rgba(50,60,70,0.25)'
});
});

test('shadow styles and array boxShadow together', () => {
expect(
preprocess({
shadowColor: 'rgba(50,60,70,0.5)',
shadowOffset: { width: 1, height: 2 },
shadowOpacity: 0.5,
shadowRadius: 3,
boxShadow: [
{
offsetX: 2,
offsetY: 3,
spreadDistance: 5,
color: 'rgba(10,20,30,0.45)',
inset: true
}
]
})
preprocess(
{
shadowColor: 'rgba(50,60,70,0.5)',
shadowOffset: { width: 1, height: 2 },
shadowOpacity: 0.5,
shadowRadius: 3,
boxShadow: [
{
offsetX: 2,
offsetY: 3,
spreadDistance: 5,
color: 'rgba(10,20,30,0.45)',
inset: true
}
]
},
options
)
).toEqual({
boxShadow:
'inset 2px 3px 0 5px rgba(10,20,30,0.45), 1px 2px 3px rgba(50,60,70,0.25)'
Expand All @@ -289,66 +304,104 @@ describe('StyleSheet/preprocess', () => {
});

describe('preprocesses multiple textShadow styles into a single declaration', () => {
const options = { textShadow: true };

test('textShadowColor only', () => {
expect(preprocess({ textShadowColor: 'red' })).toEqual({});
expect(preprocess({ textShadowColor: 'red' }, options)).toEqual({});
});

test('textShadowOffset only', () => {
expect(preprocess({ textShadowOffset: { width: 1, height: 2 } })).toEqual(
{}
);
expect(
preprocess({ textShadowOffset: { width: 1, height: 2 } }, options)
).toEqual({});
});

test('textShadowRadius only', () => {
expect(preprocess({ textShadowRadius: 5 })).toEqual({});
expect(preprocess({ textShadowRadius: 5 }, options)).toEqual({});
});

test('textShadowColor and textShadowOffset only', () => {
expect(
preprocess({
textShadowColor: 'red',
textShadowOffset: { width: 0, height: 0 }
})
preprocess(
{
textShadowColor: 'red',
textShadowOffset: { width: 0, height: 0 }
},
options
)
).toEqual({});
expect(
preprocess({
textShadowColor: 'red',
textShadowOffset: { width: -1, height: 0 }
})
preprocess(
{
textShadowColor: 'red',
textShadowOffset: { width: -1, height: 0 }
},
options
)
).toEqual({
textShadow: '-1px 0px 0px rgba(255,0,0,1.00)'
});
expect(
preprocess({
textShadowColor: 'red',
textShadowOffset: { width: 1, height: 2 }
})
preprocess(
{
textShadowColor: 'red',
textShadowOffset: { width: 1, height: 2 }
},
options
)
).toEqual({
textShadow: '1px 2px 0px rgba(255,0,0,1.00)'
});
});

test('textShadowColor and textShadowRadius only', () => {
expect(
preprocess({ textShadowColor: 'red', textShadowRadius: 0 })
preprocess({ textShadowColor: 'red', textShadowRadius: 0 }, options)
).toEqual({});
expect(
preprocess({ textShadowColor: 'red', textShadowRadius: 5 })
preprocess({ textShadowColor: 'red', textShadowRadius: 5 }, options)
).toEqual({
textShadow: '0px 0px 5px rgba(255,0,0,1.00)'
});
});

test('textShadowColor, textShadowOffset, textShadowRadius', () => {
expect(
preprocess({
textShadowColor: 'rgba(50,60,70,0.50)',
textShadowOffset: { width: 5, height: 10 },
textShadowRadius: 15
})
preprocess(
{
textShadowColor: 'rgba(50,60,70,0.50)',
textShadowOffset: { width: 5, height: 10 },
textShadowRadius: 15
},
options
)
).toEqual({
textShadow: '5px 10px 15px rgba(50,60,70,0.50)'
});
});
});
describe('shadow conversion options', () => {
test('shadow styles are not converted when options.shadow is not true', () => {
expect(preprocess({ shadowColor: 'red' })).toEqual({});
expect(preprocess({ shadowColor: 'red' }, { shadow: false })).toEqual({});
});

test('textShadow styles are not converted when options.textShadow is not true', () => {
expect(
preprocess({
textShadowColor: 'red',
textShadowOffset: { width: 1, height: 2 }
})
).toEqual({});
expect(
preprocess(
{
textShadowColor: 'red',
textShadowOffset: { width: 1, height: 2 }
},
{ textShadow: false }
)
).toEqual({});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ export const preprocess = <T: {| [key: string]: any |}>(

// Convert shadow styles
if (
(options.shadow === true,
style.shadowColor != null ||
options.shadow === true &&
(style.shadowColor != null ||
style.shadowOffset != null ||
style.shadowOpacity != null ||
style.shadowRadius != null)
Expand All @@ -154,8 +154,8 @@ export const preprocess = <T: {| [key: string]: any |}>(

// Convert text shadow styles
if (
(options.textShadow === true,
style.textShadowColor != null ||
options.textShadow === true &&
(style.textShadowColor != null ||
style.textShadowOffset != null ||
style.textShadowRadius != null)
) {
Expand Down