Categories
JavaScript Answers React Native Answers

How to render a shadow with React Native?

Spread the love

Sometimes, we want to render a shadow with React Native.

In this article, we’ll look at how to render a shadow with React Native.

How to render a shadow with React Native?

To render a shadow with React Native, we can set some shadow styles.

For instance, we write:

import * as React from 'react';
import { View, Text } from 'react-native';
import Constants from 'expo-constants';
import AssetExample from './components/AssetExample';
import { Card } from 'react-native-paper';

export default function App() {
  return (
    <View
      style={{
        padding: 10,
        margin: 10,
        shadowColor: '#000',
        shadowOffset: { width: 3, height: 2 },
        shadowOpacity: 0.2,
        elevation: 5,
      }}>
      <Text>hello world</Text>
    </View>
  );
}

to set the shadowColor, shadowOffset and shadowOpacity to add a shadow to the View.

shadowOffset adds the shadow effect.

shadowColor sets the shadow color.

And shadowOpacity sets the shadow opacity.

Conclusion

To render a shadow with React Native, we can set some shadow styles.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *