Skip to content

Commit dcee5e3

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 5bf10b1 commit dcee5e3

6 files changed

Lines changed: 31 additions & 105 deletions

File tree

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 Native, 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 & 85 deletions
This file was deleted.

src/__tests__/index.js

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

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

src/__tests__/units.js

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

118-
it('allows untis to be used with box-shadow', () => {
118+
it('allows units to be used with box-shadow', () => {
119119
expect(
120120
transformCss([['box-shadow', `10px ${value} ${value} red`]])
121121
).toEqual({
122-
shadowOffset: { width: 10, height: value },
123-
shadowRadius: value,
124-
shadowColor: 'red',
125-
shadowOpacity: 1,
122+
boxShadow: `10px ${value} ${value} red`,
126123
})
127124
})
128125
})

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)