11

Here is my style defined in the React-Native screen. I have used the elevation property to achieve a box-shadow. But it's not working properly.

const styles = StyleSheet.create({
scrollContainer: {
    flex: 1,
},
container: {
    flex: 1,
    flexDirection: "row",
    flexWrap: "wrap",
    padding: 2
},
box: {
    margin: 8,
    width: Dimensions.get('window').width / 2 - 18,
    height: Dimensions.get('window').width / 2 - 18,
    justifyContent: "center",
    alignItems: "center",
    borderStyle: 'dashed',
    borderLeftWidth: 1,
    borderTopWidth: 1,
    borderRightWidth: 1,
    borderBottomWidth: 1,
    borderTopColor: 'black',
    borderBottomEndRadius : 8,
    borderTopStartRadius: 8,
    borderTopEndRadius: 8,
    borderBottomStartRadius: 8,
    borderBottomLeftRadius:8,
    borderBottomRightRadius:8,
    elevation: 5
},
navBar:{
    backgroundColor: "#000",
}
});

I have also tried using box-shadow but the same problem arises.

Kiran Maniya
  • 8,453
  • 9
  • 58
  • 81
  • 1
    Have you tried specifing `shadowColor: Colors.BLACK, shadowOffset: { width: 0, height: 8 }, shadowOpacity: 0.16, shadowRadius: 16`? Values are clearly random :) – Milore Dec 06 '18 at 08:44

5 Answers5

36

Try to add following properties to the styles.box. You could change the values for better results.

// ...
box: {
  // ...
  shadowColor: '#000',
  shadowOffset: { width: 0, height: 2 },
  shadowOpacity: 0.5,
  shadowRadius: 2,
  elevation: 2,
},
// ...
ggorlen
  • 44,755
  • 7
  • 76
  • 106
Helmer Barcos
  • 1,898
  • 12
  • 18
2

you can use below code

          height: 150,
          width: '100%',
          backgroundColor: 'white',
          elevation: 5,
          shadowColor: '#000',
          shadowOffset: {width: 0, height: 0},
          shadowOpacity: 0.1,
          shadowRadius: 5,
Mayank Pandav
  • 425
  • 5
  • 20
1

After little investigation, I found the working solution and here it is. There is a broad discussion over this problem on the github issue.

box: {
    margin: 8,
    shadowColor: '#000',
    shadowOffset: { width: 0, height: 2 },
    shadowOpacity: 0.5,
    shadowRadius: 2,
    elevation: 2,
}

rather only using elevation property. Also, make sure you give the proper margin to the box for proper spacing. I was lacking the margin in my case. Hope it's useful findings to help.

Kiran Maniya
  • 8,453
  • 9
  • 58
  • 81
1

You can add this style in your View

 headerstyle:{
    shadowColor: '#000',
    shadowOffset: { width: 0, height: 2 },
    shadowOpacity: 0.5,
    shadowRadius: 2,
    elevation: 2,
    alignSelf: 'stretch'
},
kishan verma
  • 984
  • 15
  • 17
0
chip: {
    padding: 10,
    height: 40,
    shadowColor: 'black',
    elevation: 3,
    borderRadius: 5,
    backgroundColor: '#fff'
  }