Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reactnavigation hiding statusbar leaves space above header

I use reactnavigation and I am hiding the statusbar at the top, but it leaves an empty space above the header.

I already tried paddingTop or marginTop, but none work.

This is how I hide the statusbar.

import React from 'react';
import { Platform, View, StatusBar } from 'react-native';
import { Tabs, Drawer } from './config/router';

const App = () => (
    <View style={{flex:1}}>
        <StatusBar hidden={true} />
        <Drawer />
    </View>
);

export default App;

Any idea would be helpful.

Thanks.

like image 719
udarts Avatar asked May 25 '18 09:05

udarts


People also ask

How do I keep my layout from overlapping with iOS status bar?

This causes most layouts to overlap with the status bar. I can fix this by adding a padding to the view when loading them.

How do I hide status bar in Expo?

setStatusBarHidden(hidden, animation) If the status bar should be hidden. Animation to use when toggling hidden, defaults to 'none' .

What is forceInset?

forceInset takes an object with the keys top | bottom | left | right | vertical | horizontal and the values 'always' | 'never' . Or you can override the padding altogether by passing an integer. There is also a Snack available to demonstrate how forceInset behaves.


1 Answers

How to Fix it

I add the following to the index.js:

import React from 'react';
import { Platform, View, StatusBar } from 'react-native';
import { Tabs, Drawer } from './config/router';
import { SafeAreaView } from 'react-navigation';

SafeAreaView.setStatusBarHeight(0);

const App = () => (
    <View style={{flex:1}}>
        <StatusBar hidden={true} />
        <Drawer />
    </View>
);

export default App;

Basically added the SafeAreaView part.

Hope this is helpful for others.

like image 125
udarts Avatar answered Sep 30 '22 06:09

udarts