Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

React Native Box Shadow

Introduction to React Native Box Shadow

Shadow is an attribute which beautifies any object. Shadows are very much used in the field of web development and app development for the same purpose. The developers use it to beautify different objects used one the website. These shadows give a natural depth to the object and provide a nice customer experience. React Native provides the option of creating shadows for the objects. Box Shadow is a property used for providing shadows to different shapes; it helps in styling the shadows through various attributes like opacity, color, intensity and many more. React Native Box Shadow is available only for the iOS platform.

Syntax:

1. For the iOS platform.


shadowColor: "#b97ee0",
shadowRadius: 4.65,
shadowOffset: {
height: 4,
width: 0,
},
shadowOpacity: 10,

2. For the Android platform.


elevation: 8,

For styling the Box Shadow in React Native, only the elevation feature is supported in the Android platform, while in the iOS platform, we can style the box-shadow in many ways by setting the opacity, color, height, width, radius, etc. of the shadow.

Examples of React Native Box Shadow

Given below are the examples mentioned:

Example #1 – Basic React Native Box Shadow Usage.

A circular box is developed in the code below and #15ad9b colored shadow is developed around that circular box which is foggy in nature. Through,

boxShadow: “22px 22px 10px 22px #15ad9b”,

The first 22px defines the shadow around the circular box, the second 22px defines the intensity of the shadow, 10px also helps in defining the intensity of the shadow around the box, and the last 22px helps in defining the area of the shadow around the circular box.#15ad9b is for defining the color of the shadow as per the requirement.

Key components for the proper execution of the code are:

a. ShadowBox.js

import React from "react";
import Radium from "radium";
let Click = () =>

;
export default Radium(Click);
const styles = {
root: {
height: 100,
background: "#f071f5",
boxShadow: "22px 22px 10px 22px #15ad9b",
borderRadius: 100/2,
width: 100,
}
};

b. index.js

import React from "react";
import Button from "./ShadowBox";
import Radium from "radium";
import "./style.css";
import { render } from "react-dom";
let EduCBA = () => (






);
const styles = {
cash: {
background: "#f7f69c",
},
};
render(, document.getElementById("root"));
EduCBA = Radium(EduCBA);

c. style.css

body,
html {
background: #ad1515;
height: 100%;
}

Output:

Example #2 – With Search Bar.

A rectangular button is developed with blue shadow in the code below; similar to example 1, we have defined the styling of the shadow using box-shadow. The shadow so developed follows along to the expansion of the button to the search bar.

Key components for the proper execution of the code are:

a. index.js

import React
, { useState
, useRef
} from "react";
import ReactDOM from "react-dom";
import styled from "styled-components";
import "./styles.css";
const Click = styled.button`
border-bottom-left-radius: 100/2;
background-color: #f285ef;
color: "#f56e94";
cursor: ${props => (props.barOpened ? "pointer" : "none")};
border-color: #faf591;
line-height: 10;
pointer-events: ${props => (props.barOpened ? "auto" : "none")};
`;
const Responses = styled.input`
&::placeholder {
color: #757d7b;
}
background-color: #96faee;
border-bottom-left-radius: 100/2;
line-height: 19;
color: #2264c7;
border-color: #faf591;
width: 50%;
&:focus,
&:active {
outline: none;
}
margin-left: ${props => (props.barOpened )};
`;
const Rex = styled.form`
width: ${props => (props.barOpened
? "10"
: "2rem")};
background-color: #aff576;
display: flex;
box-shadow: 10px 9px #4977e3;
justify-content: center;
border-bottom-left-radius: 100/2;
height: 20;
cursor: ${props => (props.barOpened
? "auto"
: "pointer")};
padding: 2rem;
align-items: center;
border-color: #faf591;
`;
function Pikachu() {
const [barOpened
, setBarOpened] = useState(0);
const [input
, setInput] = useState("");
const inputFocus = useRef();
return (


barOpened={barOpened}
onClick={() => {
setBarOpened(true);
inputFocus.current.focus();
}}
onChange={e => setInput(e.target.value)}
ref={inputFocus}
value={input}
barOpened={barOpened}
placeholder="Course Finder"
/>

EDUCBA



);
}
ReactDOM.render(, document.getElementById("root"));

b. styles.css

.App {
font-family: 'Times New Roman'
, Times
, serif;
}
* {
margin: 10;
padding: 0;
}

Output:

Example #3 – Usage for Advance Purpose.

Both of example 1 & 2 are merged together to understand the usage of Box Shadow in the complex scenario.

Key components for the proper execution of the code are:

a. ShadowBox.js

import React from "react";
import Radium from "radium";
let Click = () =>

;
export default Radium(Click);
const styles = {
root: {
height: 100,
background: "#f071f5",
boxShadow: "22px 22px 10px 22px #15ad9b",
borderRadius: 100/2,
width: 100,
}
};

b. decoration.css

body,
html {
background: #f5d1c6;
}

c. index.js

import React
, { useState
, useRef
} from "react";
import "./decoration.css";
import ReactDOM from "react-dom";
import Button from "./ShadowBox";
import styled from "styled-components";
import "./styles.css";
const Click = styled.button`
border-bottom-left-radius: 100/2;
background-color: #f06b59;
color: "#f56e94";
cursor: ${props => (props.barOpened ? "pointer" : "none")};
border-color: #faf591;
line-height: 10;
pointer-events: ${props => (props.barOpened ? "auto" : "none")};
`;
const styles = {
cash: {
},
};
const Responses = styled.input`
&::placeholder {
color: #757d7b;
}
background-color: #96faee;
border-bottom-left-radius: 100/2;
line-height: 8;
color: #2264c7;
border-color: #faf591;
width: 50%;
&:focus,
&:active {
outline: none;
}
margin-left: ${props => (props.barOpened )};
`;
const Rex = styled.form`
width: ${props => (props.barOpened
? "1"
: "2rem")};
background-color: #aff576;
display: flex;
box-shadow: 50px
18px
9px #4977e3;
justify-content: center;
border-bottom-left-radius: 100/2;
height: 20;
cursor: ${props => (props.barOpened
? "auto"
: "pointer")};
padding: 2rem;
align-items: center;
border-color: #faf591;
`;
function Pikachu() {
const [barOpened
, setBarOpened] = useState(0);
const [input
, setInput] = useState("");
const inputFocus = useRef();
return (


barOpened={barOpened}
onClick={() => {
setBarOpened(true);
inputFocus.current.focus();
}}
>
onChange={e => setInput(e.target.value)}
ref={inputFocus}
value={input}
barOpened={barOpened}
placeholder="Course Finder"
/>

EDUCBA








);
}
ReactDOM.render(,  document.getElementById("root"));

d. styles.css

.App {
font-family: 'Times New Roman'
, Times
, serif;
}
* {
margin: 10;
padding: 0;
}

Output:

Conclusion

We went through multiple examples to see its application according to the different requirements of the React Native application. We came across the styling through Box Shadow and how it helps in providing a better user experience in the application.

Recommended Articles

This is a guide to React Native Box Shadow. Here we discuss the introduction to React Native Box Shadow along with examples. You may also have a look at the following articles to learn more –

  1. React Native Tab Bar
  2. React Error Boundaries
  3. React Native Swift
  4. React Native Template

The post React Native Box Shadow appeared first on EDUCBA.



This post first appeared on Best Online Training & Video Courses | EduCBA, please read the originial post: here

Share the post

React Native Box Shadow

×

Subscribe to Best Online Training & Video Courses | Educba

Get updates delivered right to your inbox!

Thank you for your subscription

×