All the small social networking chatting apps now give its users to more customized and compact view with background image customization. Now user can himself set chatting screen background image as full screen of their android and iOS applications. So in this tutorial we would going to create a simple react native app to stretch and Set Background Image as Full Screen like chatting application backgrounds. So let’s get started .
Note: The background image used in this project is created by me using Photoshop. It is a Gradient Shade Image. You can use any other image according to your requirement.
Contents in this project Set Background Image as Full Screen in React Native:
1. Import StyleSheet, View and Image component in your project.
1
|
import { StyleSheet, View, Image } from ‘react-native’;
|
2. Now we would create Root Parent View using Image component. Normally we create root view using View component but in this case we have to make root view using Image component. There is no need to worry the design looks same. We would also setting the image source using HTTP URL so it’ll be more easy to understand.
1
2
3
4
5
6
7
8
9
10
11
12
13
|
render() {
return (
<Image source={ {uri: ‘/wp-content/uploads/2017/10/sample_full_image.jpg’} } style={styles.MainContainer} >
{/* Put All Your Component Here Inside Root Image Component. */}
</Image>
);
}
|
3. Now create custom CSS class named as MainContainer . This class has all the magic because when we give the height and width as NULL then it will automatically stretch and adjust according to screen size. This will work on both Landscape and Portrait Mode.
1
2
3
4
5
6
7
8
9
10
11
|
const styles = StyleSheet.create({
MainContainer: {
flex: 1,
justifyContent: ‘center’,
alignItems: ‘center’,
width: null,
height: null,
}
});
|
4. Complete source code for App.js File :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
import React, { Component } from ‘react’;
import { StyleSheet, View, Image } from ‘react-native’;
export default class App extends Component<{}> {
render() {
return (
<Image source={ {uri: ‘/wp-content/uploads/2017/10/sample_full_image.jpg’} } style={styles.MainContainer} >
{/* Put All Your Component Here Inside Root Image Component. */}
</Image>
);
}
}
const styles = StyleSheet.create({
MainContainer: {
flex: 1,
justifyContent: ‘center’,
alignItems: ‘center’,
width: null,
height: null,
}
});
|
Screenshot in android mobile app :
Screenshot in iOS mobile application :