Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-native shadow not appearing

I'm trying to get a shadow below my views, and from what I found online it should be quite simple:

shadowOffset: { width: 10, height: 10 }, shadowColor: 'black', shadowOpacity: 1.0, 

but the problem is that the shadow is not appearing at all.

Here's my components

<View style={styles.shadow}>     <View style={styles.box} >         <View style={styles.ListComponent}>             <Text style={styles.itemText}>Livestream</Text>         </View>     </View> </View> 

and in my StyleSheet:

const styles = StyleSheet.create({     shadow: {     shadowOffset: { width: 10, height: 10 },     shadowColor: 'black',     shadowOpacity: 1.0 }, 

Any reason for this or is there something I've missed?

like image 593
smuvv Avatar asked Jul 04 '17 14:07

smuvv


2 Answers

Is the shadow working on IOs ? Android and IOS work ≠ in React-Native. For android, it works with elevation.

const styles = StyleSheet.create({ shadow: {   shadowOffset: { width: 10, height: 10 },   shadowColor: 'black',   shadowOpacity: 1,   elevation: 3,   // background color must be set   backgroundColor : "#0000" // invisible color } 

Otherwise, try to set a background color to your shadow component :)

like image 172
TBouder Avatar answered Sep 24 '22 08:09

TBouder


For iOS, raise the zIndex of your outer <View>

const styles = StyleSheet.create({    shadow: {     shadowOffset: { width: 10, height: 10 },     shadowColor: 'black',     shadowOpacity: 1,     elevation: 3,     zIndex:999,   }   
like image 30
GollyJer Avatar answered Sep 20 '22 08:09

GollyJer