Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a UI with box shadow in react native

I am trying to create a UI in react native, the UI contains a box with outer shadow. using the image I have done that, but is there any proper way to do that?

Attaching the image

like image 676
rahulvramesh Avatar asked Aug 31 '17 02:08

rahulvramesh


People also ask

How do you make a box shadow in React Native?

For adding box shadows in Android, we can use the elevation prop, which uses the Android Elevation API. Next, import the StyleSheet again to style the card: // remember to import StyleSheet from react-native const styles = StyleSheet.

How do I add a bottom shadow in React Native?

To set elevation shadow only on the bottom on React Native, we wrap out View with another View and set its overflow to 'hidden' . to set overflow to 'hidden' on the outer View . And then we add the shadow styles in the inner view to add the shadow. elevation is needed for Android to show the shadow.


1 Answers

You will have to use different style props for iOS and Android.

Android

It's very simple for android, just use the elevation style prop (See docs) . An example:

boxWithShadow: {     elevation: 5 } 

iOS

In iOS you have more flexibility, use the Shadow props (See docs). An example:

boxWithShadow: {     shadowColor: '#000',     shadowOffset: { width: 0, height: 1 },     shadowOpacity: 0.8,     shadowRadius: 1,   } 

Summary

In summary, to get box shadow for both platforms, use both sets of style props:

boxWithShadow: {     shadowColor: '#000',     shadowOffset: { width: 0, height: 1 },     shadowOpacity: 0.8,     shadowRadius: 2,       elevation: 5 } 

Attention: Do not use overflow: 'hidden';, in iOS all of the shadows disappear by this property.

like image 113
Sarath S Menon Avatar answered Sep 19 '22 14:09

Sarath S Menon