I tried a lot of suggestions but this one really worked!! For this we need to import the Dimensions
component from react-native
.
import { Dimensions } from 'react-native';
Store the height and width dimensions of the screen into variables:
const screenHeight = Dimensions.get('window').height;
const screenWidth = Dimensions.get('window').width;
Then set the height and width of the background image to the value of those variables:
<ImageBackground
source={{
uri: 'example.png',
}}
style={{
height: screenHeight,
width: screenWidth,
}} >
// Other components
</ImageBackground>
You can refer to https://www.geeksforgeeks.org/how-to-set-background-image-in-react-native/