Categories
React Native Answers

How to add transparent overlay in React Native and JavaScript?

Spread the love

Sometimes, we want to add transparent overlay in React Native and JavaScript.

In this article, we’ll look at how to add transparent overlay in React Native and JavaScript.

How to add transparent overlay in React Native and JavaScript?

To add transparent overlay in React Native and JavaScript, we add transparent styles for the View.

For instance, we write

import { View, StyleSheet } from "react-native";

const styles = StyleSheet.create({
  overlaycontainer: {
    ...StyleSheet.absoluteFillObject,
    backgroundColor: "#000",
    opacity: 0.8,
    justifyContent: "center",
    alignItems: "center",
  },
});

//...

<View style={styles.overlaycontainer}>
  <Text style={{ color: "#fff" }}>Locating directions please wait ...</Text>
</View>

to add styles with the opacity value with StyleSheet.create.

Then we use the styles.overlaycontainer styles for the View.

Conclusion

To add transparent overlay in React Native and JavaScript, we add transparent styles for the View.

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 *