Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native how to customize android elevation shadow

Tags:

react-native

Using android-specific style rule, elevation, I get a nasty "halo" effect when using. for example, this image shows elevation: 20:

bigger "halo" effect

Even a small elevation 1,2, or 3 gives the appearance that the element is "haloed"/has a border (bad)

smaller "halo" effect

How can I add more customization to the android-specific shadow to get rid of halo effect. iOS has specific rules like shadowOpactiy, shadowRadius, shadowOffset–but I don't see anything for android.

like image 470
thurt Avatar asked Feb 13 '17 18:02

thurt


People also ask

How do I change the elevation shadow color in React Native?

Unfortunately, the color of the shadow produced by Android's setElevation cannot be changed. Also, their Material Design guidelines around the web like here don't seem to indicate that you can change the color. In addition, box shadows in React Native are also not supported on Android, based on this.

How do you increase shadow in React Native?

elevation is an Android-only style property available on the View elements. If you're open to 3rd party software, another way to get shadows for android is to install react-native-shadow . Be careful when using elevation as it won't respect your settings for shadow , such as the color and offset.

How do I add a shadow color 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.


1 Answers

According to the official documentation there is no such thing as shadowopacity or any way to change the default shadow since is there by design, by "material design" Source: https://developer.android.com/training/material/shadows-clipping

But what you can do is to use a component with a dummy view that has the desired border and then just use it in your render function like

render(){
  <View style={{flex:1}}>
    <Viewwithborder>
     //pass the item you want to have custom elevation here
    </Viewwithborder>
  </View>
}

and in your custom "viewwithborder" you just do this

   render(){
   <View style={{styles.CustomElevationStyle}}>
      {this.props.children}
   </View> 
}
like image 156
ValdaXD Avatar answered Oct 27 '22 11:10

ValdaXD