Reputation: 63
I tried to fill the whole screen with black using flex: 1
. but the result is like this
<View
style={{
flex: 1,
backgroundColor: 'black',
}}
/>
i've also tried using:
height: '100%',
width: '100%',
and
const HEIGHT = Dimensions.get('window').height;
const WIDTH = Dimensions.get('window').width;
but the result is still the same.
is there a way to completely fill the whole screen?
Upvotes: 2
Views: 9495
Reputation: 194
First wrap your view component in SafeAreaView then provide a flex style to it.
<SafeAreaView style={{flex: 1}}>
<View style={/* do your styling */}>...</View>
</SafeAreaView>
Upvotes: 1
Reputation: 126
I have had similar problem. But in my case, I have solved the problem by modifying View to SafeAreaView in App.js (especially return() session) and other related files.
Upvotes: 0
Reputation: 271
Try this if you are using react navigation
const ReactNavigation = require('react-navigation');
ReactNavigation.SafeAreaView.setStatusBarHeight(0);
or
navigationOptions: {
headerForceInset: {top: 'never'},
}
Upvotes: 1
Reputation: 2918
First import:
import { StatusBar } from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";
Change your layout to:
<StatusBar backgroundColor="black" barStyle="white-content"/>
<SafeAreaView
style={{
flex: 1,
backgroundColor: 'black',
}}
>
<View>...</View>
</SafeAreaView>
Upvotes: 3
Reputation: 34
If you given padding of parent view, so remove it. May be it work and Your render function it should be like this.
render() {
return (
<View style={{ flex: 1, backgroundColor: 'black'}} />
)
}
Upvotes: -1
Reputation: 604
Are you wrapping your app inside safe area view, anyway you can use percentage width and heights to fill the entire screen if flex:1 is not working.
style = {{ width:'100%', height:'100%' }}
Upvotes: 2
Reputation: 426
You can user Dimensions.get('window') to get the full height and width of the screen.
declare a const
const HEIGHT = Dimensions.get('window').height;
const WIDTH = Dimensions.get('window').width;
then use this inside style
style = {{
height = HEIGHT,
width = WIDTH,
backgroundColor = 'black',
}}
Upvotes: 0