Important
The new React Native 0.76, released on Oct 23, 2024, finally supports a cross-platform shadow!
This new feature should be preferred over this library.
I can only wholeheartedly appreciate everyone's support and kindness over the past 4 years and celebrate having reached 40k weekly and 2M+ total downloads 🤗
react-native-shadow is dead for years. This is an improved version with more functionalities, TypeScript support, and written from scratch. It's not required to define its size: the shadow is smartly applied on the first render and then precisely reapplied on the following ones.
It solves the old React Native issue of not having the same shadow appearance and usage for Android, iOS, and Web.
Compatible with Android, iO,S and Web. And Expo!
Supports RTL.
Give this library a quick try!
1. First, install react-native-svg.
The latest
react-native-svgversion is recommended, including if using Expo.
npm i react-native-shadow-2
# or
yarn add react-native-shadow-2import { Shadow } from 'react-native-shadow-2';
<Shadow>
<Text style={{ margin: 20, fontSize: 20 }}>🙂</Text>
</Shadow><Shadow distance={15} startColor={'#eb9066d8'} endColor={'#ff00ff10'} offset={[3, 4]}>
<View style={{ borderTopStartRadius: 24, borderBottomEndRadius: 0, borderRadius: 10, backgroundColor: '#c454f0dd' }}>
<Text style={{ margin: 20, fontSize: 20 }}>🤯</Text>
</View>
</Shadow>-
If the Shadow has a single child, it will get the
width,heightand all of theborderRadiusproperties from the children'sstyleproperty, if defined. -
You may also define those properties in the Shadow's
style. The defined properties here will have priority over the ones defined in the child'sstyle. -
If the
widthandheightare defined in any of those, there will be only a single render, as the first automatic sizing won't happen, only the precise render. -
You can use either the
'borderTopLeftRadius'or'borderTopStartRadius'and their variations to define the corners radii, although I recommend the latter as it's the RTL standard. -
Having a radius greater than its side will mess the shadow if the sizes aren't defined. You can use the
safeRenderproperty to only show the shadow on the 2nd render and beyond, when we have the exact component size and the radii are properly limited. -
Radii greater than 2000 (Tailwind's
rounded-fullis 9999) may crash Android.
-
The opacity is set directly in the
startColorandendColorproperties, in the alpha channel. E.g.:'#0001'is an almost transparent black. You may also use'#rrggbbaa','rgba()','hsla()'etc. All patterns in this link, but not int colors, are accepted. -
Use the
stretchproperty orstyle={{alignSelf: 'stretch'}}in your Shadow component. Explanation! -
It's exported the
ShadowPropstype, the props of the Shadow component. You may do the following:const ShadowPresets = { button: { offset: [0, 1], distance: 1, startColor: '#0003', } as ShadowProps, }; <Shadow {...ShadowPresets.button}>
-
Upgrade your Typescript to at least 4.0.0! Those two properties use labeled tuples. If you don't use Typescript, this won't happen.


