Skip to content

Commit d6e7c31

Browse files
committed
Add support for box-shadow and filter properties
React Native supports box-shadow and filter properties natively since version 0.76. This means that every version of React Native that is stil supported can benefit from box-shadow and filter properties.
1 parent f3baa13 commit d6e7c31

7 files changed

Lines changed: 31 additions & 103 deletions

File tree

.DS_Store

6 KB
Binary file not shown.

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ margin: 5px 7px 2px;
6363
}
6464
```
6565

66-
Shorthands will only accept values that are supported in React, so `background` will only accept a colour, `backgroundColor`
66+
Shorthands will only accept values that are supported in React, so `background` will only accept a colour, `backgroundColor` will not accept an image, and `font` will not accept font-variant values that React Native does not support.
6767

68-
There is also support for the `box-shadow` shorthand, and this converts into `shadow-` properties. Note that these only work on iOS.
68+
React Native's `box-shadow` and `filter` properties are passed through as
69+
`boxShadow` and `filter`, so support depends on your React Native version.
6970

7071
#### Shorthand Notes
7172

src/__tests__/boxShadow.js

Lines changed: 0 additions & 83 deletions
This file was deleted.

src/__tests__/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,32 @@ it('allows CSS custom properties to pass through', () => {
9292
expect(transformCss([['--my-prop', '0%']])).toEqual({ '--my-prop': '0%' })
9393
})
9494

95+
it('passes filter through as a raw React Native property', () => {
96+
expect(transformCss([['filter', 'opacity(0.5)']])).toEqual({
97+
filter: 'opacity(0.5)',
98+
})
99+
})
100+
101+
it('passes multiple filter functions through unchanged', () => {
102+
expect(transformCss([['filter', 'opacity(0.5) blur(5px)']])).toEqual({
103+
filter: 'opacity(0.5) blur(5px)',
104+
})
105+
})
106+
107+
it('passes box-shadow through as a raw React Native property', () => {
108+
expect(transformCss([['box-shadow', '10px 20px 30px red']])).toEqual({
109+
boxShadow: '10px 20px 30px red',
110+
})
111+
})
112+
113+
it('passes multiple box-shadow values through unchanged', () => {
114+
expect(
115+
transformCss([['box-shadow', '5px 5px 5px red, -5px -5px 5px green']])
116+
).toEqual({
117+
boxShadow: '5px 5px 5px red, -5px -5px 5px green',
118+
})
119+
})
120+
95121
it('allows percent in unspecialized transform', () => {
96122
expect(transformCss([['top', '0%']])).toEqual({ top: '0%' })
97123
})

src/__tests__/units.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,11 @@ lengthUnits.forEach(unit => {
113113
})
114114
})
115115

116-
it('allows untis to be used with box-shadow', () => {
116+
it('allows units to be used with box-shadow', () => {
117117
expect(
118118
transformCss([['box-shadow', `10px ${value} ${value} red`]])
119119
).toEqual({
120-
shadowOffset: { width: 10, height: value },
121-
shadowRadius: value,
122-
shadowColor: 'red',
123-
shadowOpacity: 1,
120+
boxShadow: `10px ${value} ${value} red`,
124121
})
125122
})
126123
})

src/transforms/boxShadow.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/transforms/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
} from '../tokenTypes'
99
import aspectRatio from './aspectRatio'
1010
import border from './border'
11-
import boxShadow from './boxShadow'
1211
import flex from './flex'
1312
import flexFlow from './flexFlow'
1413
import font from './font'
@@ -58,7 +57,6 @@ export default {
5857
borderColor,
5958
borderRadius,
6059
borderWidth,
61-
boxShadow,
6260
flex,
6361
flexFlow,
6462
font,

0 commit comments

Comments
 (0)