Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply shadow to react native View without affecting inner view elements?

Please click on image

I would like to know how to apply shadow only to the main outer view. Here on applying shadow, it's getting applied to all the inner elements

like image 851
Jacob Lukose Avatar asked Oct 21 '18 11:10

Jacob Lukose


People also ask

How do I apply shadow on view in React Native?

🤖 How to apply shadows on Android platform On Android, we need to use the elevation view style prop from react-native to add shadows. elevation: Sets the elevation of a view, using Android's underlying elevation API. This adds a drop shadow to the item and affects z-order for overlapping views.

How do you give a box shadow only in bottom 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.

How do you make a shadow effect 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.


Video Answer


1 Answers

The trick to make the shadow props of parent don't inherit to children element, is to set a background color to the component on which you set the shadow. For example that would be:

<View 
  style={{ backgroundColor: '#fff' }}
  shadowOffset={{height: 10}}
  shadowColor='black'
  shadowOpacity={0.5}
>
  <Text>{title}</Text>
</View>

Unfortunately this only works with colored backgrounds – when setting a transparent background with RGBA or 'transparent' is doesn't help.

like image 65
Diego Unanue Avatar answered Oct 01 '22 11:10

Diego Unanue