Skip to content

Learn

Shadow effects in react native: 7 useful examples

Master React Native shadows across iOS and Android. Learn best practices, cross-platform fixes, and how Tricentis Testim Mobile validates UI at scale.

react native shadow effects

React Native shadow effects are a bit tricky. They work well in iOS but have limitations in Android. Because React Native is mainly used for cross-mobile development, we have to keep that in mind while writing the code. Luckily, there are ways to create code that runs on both platforms.

In this post, we’ll show you shadow effects using various examples. First, we’ll teach you about applying shadow effects on both iOS and Android devices, then how to add common shadow effects on both platforms. Next, we will walk through how to add shadows using the React Native library of react-native-drop-shadow. We’ll also show you how to apply shadows to an image, as well as share an advanced layout created using shadows. Lastly, we will share how to apply shadows to text elements.

You’ll want to have basic knowledge of React Native so you can follow along.

React native project

We are going to use React Native CLI and will run both the Android emulator and iOS simulator.

We are creating a new project and naming it “RNshadows.” To create a new project, run the below command:

npx react-native init RNshadows

We will see the below screen if installation is successful:

installation

Starting on iOS simulator

We will first start the project with the command npx react-native start.

native start

In another terminal, run the command npx react-native run-ios to start the project in the iOS simulator.

react native run ios

The app component

We will have different tabs to show different shadow effects. Go to the App.js file and remove its content. Now the state of the active tab will be set using useState hook.

Here we have a SafeAreView, which shows the components ShadowOne, ShadowTwo, ShadowThree, ShadowFour, ShadowFive, or ShadowSix based on the active state. Click on any tab, and the basic component will be shown.

shadowsix

Now we will add the styles for our app component.

app components

The iOS shadow

The shadow in iOS can be made easily with shadow props. This has four properties, and all of them work in iOS. Let’s first learn about them.

  • shadowColor determines the shadow color. It works in both Android and iOS.
  • shadowOffset determines the shadow position in relation to the box. It works only in iOS.
  • shadowOpacity determines the shadow transparency. It works only in iOS.
  • shadowRadius determines the blur radius of the shadow. It again works only in iOS.

Create a components folder in the root directory. Create a file called ShadowOne.js inside it. Here we are creating a simple card by giving styles to a View. We also have text with styles inside it.

In the card, we also have a style of iosProp. It gives all the shadow props discussed earlier. In the iOS simulator, we can see a nice shadow being displayed.

ios shadow

The android shadow

The above code results in problems in Android. But first, we will run it in the Android emulator. Run the command npx react-native run-android from the project directory.

Once the app runs on the Android emulator, we can see that all the shadow props are not there. We are not able to see any shadows on Android.

android shadow

Since Android doesn’t have shadowOffset, shadowRadius, or shadowOpacity, we are not getting any shadows. In Android, we have to use elevation in place of these. It is a combination of all three props.

We need to update our code to have this, and then we will get shadows.

shadowoffset

Shadows on both platforms

Now, we cannot write a different code for both platforms and maintain and deploy. In cases like this where code differs with platforms, we use the Platform API.

Add the below code in the ShadowTwo.js file. Here the main difference from the earlier code is the Platform API. We are using it inside the StyleSheet. And we are specifying the platform here within …Platform.select().

So we are giving the code for both iOS and Android in it. Now when the app runs on Android, the Android code will be picked up. In the Android code, we have a blue shadow and elevation.

shadows on both platform

Similarly, when the app runs on an iOS device, then the iOS code will be picked up. In iOS code, we have a black shadow and all shadow props.

shadow props

Using react-native-drop-shadow

When we write with Platform API, we are writing two sets of code. Instead of doing this, we can use the react-native-drop-shadow library. This library changes the iOS code to Android code when we use an Android device. For this, first install the library using the below command:

npm i react-native-drop-shadow

Now our code can just have the iOS code. Add the below code in a ShadowThree.js file. Here we are first importing DropShadow from react-native-drop-shadow. After that, wrap the View component with it. We have now moved the shadow property in commonProp in the DropShadow component.

We can see the drop shadow in the Android emulator, even though the styles are for iOS.

drop shadow

The shadows are being shown perfectly on an iOS device also.

shadow ios

Showing images with shadow

Now we will share an example to show a centered image with a box shadow. Create a file called ShadowFour.js and add the below content. Here we are again using Platform API and adding different code for box shadows for iOS and Android.

Inside the View containing the shadow code, we have an Image element. This gets a random image from the placeimg. We are making it cover to fit correctly and also giving it a width and height of 300. The shadow is shown perfectly around the image on an iOS device.

image shadow

For the Android device, we were getting only a little shadow with an elevation of 10. So we changed it to 20, and now we are getting a nice shadow.

elevation shadow

Showing advanced layout

Now let’s see an advanced layout with a box shadow. In the ShadowFive.js file, add the below content. Here we have a container wrapping four children. The first and the last View are to give space only.

The View of boxLayout contains the leftContainer and rightContainer view. Each of them contains two more Views: leftBox1, leftBox2 in leftContainer, rightBox1, and rightBox2 in rightContainer.

Note that leftBox1 and leftBox2 are laid out opposite of rightBox1 and rightBox2. We have also added our shadow properties and elevation in leftBox1, leftBox2, rightBox1, and rightBox2.

import { StyleSheet, Text, View } from 'react-native'
import React from 'react'
const ShadowFive = () => {
return (
 <View style={styles.container}>
    <View style={styles.extraSpaceUp}></View>
    <View style={styles.boxLayout}>
     <View style={styles.leftContainer}>
       <View style={styles.leftBox1}></View>
       <View style={styles.leftBox2}></View>
    </View>
    <View style={styles.rightContainer}>
       <View style={styles.rightBox1}></View>
       <View style={styles.rightBox2}></View>
    </View>
   </View>
   <View style={styles.extraSpaceDown}></View>
 </View>
 )
}
const styles = StyleSheet.create({
   container: { flex:1 },
   extraSpaceUp: { flex:1, backgroundColor:'white' },
   boxLayout: { flex:3, backgroundColor:'white', flexDirection:'row' },
   leftContainer: { flex:1, backgroundColor:'white', marginRight:'2.5%', marginLeft:'7%', marginVertical:'2%' },
   leftBox1: { flex:1, backgroundColor:'white', marginBottom:'8%', borderRadius:15, shadowColor:"#000",
   shadowOffset: { width:0, height:2 }, shadowOpacity:0.25, shadowRadius:3.84, elevation:10 },
   leftBox2: { flex:2, backgroundColor:'white', borderRadius:15, shadowColor:"#000",
     shadowOffset: { width:0, height:2 }, shadowOpacity:0.25, shadowRadius:3.84, elevation:10 },
   rightContainer: { flex:1, backgroundColor:'white', marginLeft:'2.5%', marginRight:'7%', borderRadius:15, marginVertical:'2%' },
   rightBox1: { flex:2, backgroundColor:'white' , marginBottom:'8%', borderRadius:15, shadowColor:"#000",
    shadowOffset: { width:0, height:2 }, shadowOpacity:0.25, shadowRadius:3.84, elevation:10},
   rightBox2: { flex:1, backgroundColor:'white', borderRadius:15, shadowColor:"#000",
    shadowOffset: { width:0, height:2 }, shadowOpacity:0.25, shadowRadius:3.84, elevation:10},
   extraSpaceDown: { flex:1, backgroundColor:'white' },
})
export default ShadowFive

Now we get beautiful boxes in our iOS simulator.

advance layout

Now we get beautiful boxes in our iOS simulator.

Text shadows

Text shadows work well on both platforms. We don’t have elevation for Android, so in the ShadowSix.js file, add the below content. Here we have applied the text shadow to a Text component.

Text shadows work well on both platforms.

Also, we have the textShadowOffset, textShadowColor, and textShadowRadius properties. They are exactly similar to the box shadow properties we shared earlier.

Our Android emulator is showing perfect text with black shadows.

text shadows

It is also showing perfectly in the iOS simulator.

ios simulator

Testing the App

We are done with the app, so it’s time to test it. We can write easy test cases with Jest. First, remove the App-test.js file in the __tests__folder. Now create two files in it: ShadowOne-test.js and ShadowTwo-test.js.

Add the below content in the ShadowOne-test.js file. Here we are writing a test case to match the component rendered on the mobile device.

testing app

In the ShadowTwo-test.js file, add similar content.

shadow two test

To run all the test cases, give the command npm run test from the terminal.

npm run test

All of our test cases ran successfully. If we add interactivity to the test cases (clicking on each tab), that would require us to write complicated test cases.

Testing with Tricentis Testim Mobile

Instead of writing complex interaction-heavy test scripts, you can use Tricentis Testim Mobile to validate your app the way real users interact with it.

With Tricentis Testim Mobile, you can:

  • Upload your APK or IPA
  • Interact with the app visually (taps, swipes, navigation)
  • Automatically generate resilient test flows
  • Validate UI behavior across real devices and OS versions
  • Receive actionable test results without brittle code

This approach is especially effective for visually rich React Native apps where layout, depth, and shadows play a key role in user experience.

Wrap-up

In this post, we explored how to create and manage shadow effects in React Native across iOS and Android. You learned:

  • Why shadow behavior differs between platforms
  • How to use Platform APIs for shared styling
  • How to simplify shadow logic with react-native-drop-shadow
  • How to apply shadows to images, layouts, and text
  • How to validate UI behavior using Jest

For teams looking to go beyond basic unit tests, Tricentis Testim Mobile provides a powerful way to test real-world UI interactions—without writing fragile test scripts—so your React Native apps look and behave exactly as intended on every device.

Learn more about Tricentis Testim Mobile and mobile test automation here:

Author:

Guest Contributors

Date: Jan. 29, 2026
Author:

Guest Contributors

Date: Jan. 29, 2026

You may also be interested in...