React Native Shadow Styles not working on View Component - react-native

I was wondering if anyone knew anyway to make the shadow styles on a react native view component work. I scavenged all of the web and could not find any solutions. My code is shown below:
//Stylesheet code:
...
profileImage: {
width: 170,
height: 170,
overflow: "hidden",
marginLeft: (Dimensions.get('window').width/2) - 85,
marginTop: 30,
borderRadius: 170,
shadowColor: '#000',
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.8,
shadowRadius: 2,
elevation: 5
},
...
//View component:
<View style={styles.profileImage}>
<Image source={require("../assets/images/temporaryProfilePicture.jpg")} style={styles.image} resizeMode="cover"></Image>
</View>
...
Any and all help would be largely appreciated. Thank you in advance!

This is what ive achieved with your code and link to it :expo-snack :
import * as React from 'react';
import { Text, View, StyleSheet,Dimensions ,Image} from 'react-native';
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<Image source={{uri:'https://source.unsplash.com/random'}} />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
width: 170,
height: 170,
overflow: "hidden",
marginLeft: (Dimensions.get('window').width/2) - 85,
marginTop: 30,
borderRadius: 170,
shadowColor: '#000',
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.8,
shadowRadius: 2,
elevation: 5
},
paragraph: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
},
});

Related

Blur on border in react native

How can i do blur on border such like this in ReactNative on IOS:
I tried to do it with shadow:
borderRadius: 7,
paddingVertical: 10,
paddingHorizontal: 14,
shadowColor: 'black',
shadowOffset: {
width: 0,
height: 0
},
shadowRadius: 2,
shadowOpacity: 0.2,
backgroundColor: 'white'
But it does not have the same result
Apply style
dropShadow:{
shadowColor: '#000',
shadowOpacity: 0.5,
shadowRadius: 5,
elevation: 2,
}
Working example
Link: https://snack.expo.io/#msbot01/referencefor
Full code:
import React, { Component} from 'react';
import { View, Text, StyleSheet} from 'react-native';
class App extends Component {
constructor(props) {
super(props);
}
render() {
return(
<View style={styles.container}>
<View style={[{height:100, width:100, borderWidth:0, borderRadius:10},styles.dropShadow]}>
</View>
</View>
)
}}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
justifyContent:'center',
alignItems:'center'
},
dropShadow:{
shadowColor: '#000',
shadowOpacity: 0.5,
shadowRadius: 5,
elevation: 2,
}
});
export default App;

React Native shadow left and right only

I'm having a hard time setting some shadow only for the left and right part of a view like this: imgur
I've been trying to work out the properties on react-native-shadow-generator website but to no success. Anyone knows how / if this is possible to be achieved in react-native?
You can do like this:
return (
<View style={styles.mainContainer}>
<View elevation={5} style={styles.boxStyle}>
<Text>Box 1</Text>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
mainContainer: {
backgroundColor: '#ebebeb',
padding: 10,
height : height
},
boxStyle: {
backgroundColor: '#fff',
alignItem: 'center',
justifyContent: 'center',
flexDirection: 'column',
marginLeft: 30,
marginTop: 15,
width: 120,
height: 120,
padding: 12,
borderRadius: 8,
shadowColor: "00000",
shadowOpacity: 0.9,
shadowRadius: 4,
shadowOffset: {
height: 2,
width: 2
}
}
});

React Native custom button styling issue

I am designing custom button in react native through TouchableOpacity. So far I have tried different styling approaches but didn't get like required design. below mentioned is my attempt to solve.
<TouchableOpacity style={styles.numericButton}>
<View>
<Text style={styles.numericButtonText}>1</Text>
</View>
</TouchableOpacity>
const styles = StyleSheet.create({
numericButton: {
margin:10,
padding:10,
backgroundColor:'#D3D3D3',
borderColor:'#000',
borderWidth:2,
borderRadius:5,
elevation:10,
shadowOffset: { width: 5, height: 5 },
shadowColor: "black",
shadowOpacity: 1,
shadowRadius: 5,
},
numericButtonText:{
fontSize:24,
fontWeight:'bold',
fontFamily:'Cochin'
}
});
result:
I want to style my react native button like this
We can achieve same type of button with react-native-linear-gradient
👆🏽was achieved with:
<TouchableOpacity>
<LinearGradient
// start={{x: 0.5, y: .5}} end={{x: 1, y: 1.0}}
style={styles.button}
locations={[0.3, 0, 0]}
colors={['#A8AFB5', 'white', 'white']}
>
<Text style={styles.buttonText}>{props.data}</Text>
</LinearGradient>
</TouchableOpacity>
const styles = StyleSheet.create({
button: { flex: 1, flexDirection: 'row', justifyContent: 'center', alignItems: 'center', borderRadius: 5, width: null, height: 81,marginTop:5, borderWidth: 1 },
buttonText: {
//textAlign:'center',
fontSize: 24,
fontWeight: 'bold',
fontFamily: 'Cochin',
color: 'black'
}
});
Use following style and use more gradient to set the colors matching the design and check the reflected changes
numericButton: {
alignItems: 'center',
margin: 10,
padding: 10,
backgroundColor: '#D3D3D3',
borderColor: '#000',
borderWidth: 2,
//borderRadius:5,
elevation: 5,
shadowOffset: { width: 5, height: 5 },
shadowColor: 'grey',
shadowOpacity: 1,
shadowRadius: 5,
},
numericButtonText: {
fontSize: 24,
fontWeight: 'bold',
fontFamily: 'Cochin',
},
You're good to go!

How do I get shadow to show up in react native iOS?

My shadow is not working on iOS.
What am I doing wrong?
const styles = StyleSheet.create({
container: {
backgroundColor:'#F8F8F8',
alignItems:'center',
justifyContent:'center',
height:60,
paddingTop: 20,
borderBottomWidth:0,
shadowColor: '#000000',
shadowOffset: {
width: 0,
height: 5
},
shadowRadius: 10,
shadowOpacity: 0.5,
elevation:3,
position:'relative',
},
});
You can use this to generate shadows for both iOS and Android
React native shadow generator
In fact, I tried it and it works fine on my already created TouchableOpacity Text:
<TouchableOpacity style={styles.TestView} onPress={()=> { this.doAction; }}
>
<Text style={[styles.normalText, styles.headerText, { color: colors.lighterPrimaryColor }]}>
TEST
</Text>
</TouchableOpacity>
And in style:
privateMessagesView: {
flexDirection: 'row',
backgroundColor: '#F8F8F8',
alignItems: 'center',
justifyContent: 'center',
height: 60,
paddingTop: 20,
borderBottomWidth: 0,
shadowColor: '#000000',
shadowOffset: { width: 0, height: 5 },
shadowRadius: 10,
shadowOpacity: 0.5,
elevation: 3,
position: 'relative',
},
And here's the results on my android device:
If you want better results you can use react-native-cardview or you can use a card from a UI components library like native-base, react-native-material-design ..etc If you're using one.
Shadow in react native
import {Platform} from "react-native";
add below styles to View
{
backgroundColor: '#fff',
...Platform.select({
android: {
elevation: 2,
},
ios: {
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 1,
},
shadowOpacity: 0.2,
shadowRadius: 1.41,
},
}),
}
Try this (working for me):
justifyContent: 'center',
alignItems: 'center',
backgroundColor: "#fff",
flexDirection: "row",
marginTop: 15,
height: 35,
width: 170,
marginHorizontal: 20,
marginBottom : 10,
shadowColor: '#000000',
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.5,
shadowRadius: 5,
elevation: 1.5,
borderColor: '#e6e6e6'

Shadow in button in react native

I wanna achieve button with shadow in react native with no border and spread, I have tried something like this,
{
shadowColor: 'black',
shadowOpacity: 0.8,
elevation: 6,
backgroundColor : "#0000",
shadowRadius: 15 ,
shadowOffset : { width: 56, height: 13},
borderWidth:0,
borderRadius:0,
}
But the shadow is not spreading and offset is not also working as expected. I want to achieve something like this,
Codepen
Tried adding it directly on Button but no luck. You can try this way by using TouchableOpacity.
import React, { Component } from 'react';
import { View, StyleSheet, Button, TouchableOpacity } from 'react-native';
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<TouchableOpacity style={styles.button}>
<Button title="Submit" />
</TouchableOpacity>
<TouchableOpacity style={styles.buttonHover}>
<Button title="Submit" />
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#ecf0f1',
},
button: {
borderRadius:25,
paddingTop: 5,
paddingBottom: 5,
paddingLeft: 50,
paddingRight: 50,
backgroundColor: '#FFFFFF',
shadowColor: 'rgba(0, 0, 0, 0.1)',
shadowOpacity: 0.8,
elevation: 6,
shadowRadius: 15 ,
shadowOffset : { width: 1, height: 13},
},
buttonHover: {
marginTop: 10,
borderRadius:25,
paddingTop: 5,
paddingBottom: 5,
paddingLeft: 50,
paddingRight: 50,
shadowColor: 'rgba(46, 229, 157, 0.4)',
shadowOpacity: 1.5,
elevation: 8,
shadowRadius: 20 ,
shadowOffset : { width: 1, height: 13},
backgroundColor: '#2EE59D',
color: '#FFFFFF'
}
});