Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ImageBackground to set background image for screen in react-native

When I use in react-native it gives warning that using with children is deprecated and will be error in future. User instead.

So, If I use it doesn't give expected result which I was getting using

Here is the code I wrote for using

<ImageBackground source={require('../../img/splash/splash_bg.png')} style={styles.backgroundImage} >         </ImageBackground> 

And style code is

const styles = StyleSheet.create({ backgroundImage: {     flex: 1,     // width: undefined,     // height: undefined,     // flexDirection: 'column',     // backgroundColor:'transparent',     // justifyContent: 'flex-start',   },} 

Expected result: getting when using <Image> Result using <ImageBackground>

like image 348
Waqas Avatar asked Oct 23 '17 10:10

Waqas


People also ask

How do I add a background image in React Native?

Approach: In this article, we will see that how to set background Image in react-native. In our project, we will simply set a background image and show a text input on top of it. Step 2: Create a components folder inside your project. Inside the components, folder create a file BackgroundImage.

How do you use ImageBackground?

How to use ImageBackground. The ImageBackground component accepts mostly the same props as the Image component with a few differences. The style prop is applied to a view that wraps an inner image; the imageStyle prop is applied to the image itself. The imageRef prop also is applied to the inner image.

How do I set full screen background color in React Native?

You can change the background of main activity/screen, by specifying backgroundColor attribute of stylesheet design in parent view layout (or RoorView) . This will make App's starting screen look and feel better.


1 Answers

You can use "ImageBackground" component on React Native.

<ImageBackground   source={yourSourceFile}   style={{width: '100%', height: '100%'}} >      <....yourContent...> </ImageBackground> 
like image 162
Tiago Gouvêa Avatar answered Oct 22 '22 02:10

Tiago Gouvêa