Hello Friends đź‘‹,
Welcome To Infinitbility! ❤️
This article will help you to the background image in react native, here you will get examples of ImageBackground react-native component, an example of overlay in react native, add Text upper then image in react native.
Let’s start today article ImageBackground In React Native
Introduction
Well, if you come from web development there we get the style background-image
attribute to full fill our requirement but in react native background-image
style is not available. I.e React Native provide <ImageBackground>
component.
ImageBackground usages
We are going to see an example of ImageBackground of React Native, on below example you will get answers to the following questions
How to add background image in react native How to add an overlay on the background image in react native How to add content on the background image in react native
ImageBackground.js
import React from "react";
import { ImageBackground, StyleSheet, Text, View } from "react-native";
const image = { uri: "https://reactjs.org/logo-og.png" };
const ImageBackgroundComponent = () => (
<View style={styles.container}>
<ImageBackground source={image} resizeMode="cover" style={styles.image}>
<Text style={styles.text}>Infinitbility</Text>
</ImageBackground>
</View>
);
const styles = StyleSheet.create({
container: {
flex: 1
},
image: {
flex: 1,
justifyContent: "start",
},
text: {
flex: 1,
color: "white",
fontSize: 42,
lineHeight: 84,
fontWeight: "bold",
textAlign: "center",
backgroundColor: "#000000c0"
}
});
export default ImageBackgroundComponent;
ImageBackground Image styles example
React Native provides imageStyle
attribute to manage image styling of background image or provide the style
attribute to manage the style of view.
When you want style images like border, borderRadius, resizeMode, image height and width, opacity, and tint color.
For example visit the below link. Here explain every attribute one by one.
https://reactnative.dev/docs/image-style-props
Thanks For Reading…