Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS (React native): Unnecessary space from the top of the header rendered using react navigation

Route Config

/**
 * Author: Rahul
 * Date: 25 Feb 2018
 *
 * Routes
 * @flow
 */
import React from 'react';
import { View, Text } from 'react-native';
import { StackNavigator } from 'react-navigation';
import LoginScreen from 'src/containers/login';
import HomeScreen from 'src/containers/home';
import FeedsScreen from 'src/containers/feeds';
import { AppLogo } from 'src/components';
import { background } from 'src/styles/';
import { SIGNED_IN, SIGNED_OUT, HOME, LOGIN, FEEDS } from './constants';

const navigationOptions = {
  navigationOptions: {
    headerLeft: (
      <View>
        <Text>Hamburger</Text>
      </View>
    ),
    headerRight: (
      <AppLogo />
    ),
    headerStyle: {
      paddingHorizontal: 16,
      backgroundColor: background.color2,
    },
    gesturesEnabled: false,
  },
};

const SignedOutRouteConfig = {
  [LOGIN]: { screen: LoginScreen },
};

const SignedInRouteConfig = {
  [HOME]: { screen: HomeScreen },
  [FEEDS]: { screen: FeedsScreen },
};

const SignedOut = StackNavigator(SignedOutRouteConfig, navigationOptions);
const SignedIn = StackNavigator(SignedInRouteConfig, navigationOptions);

const createRootNavigator = (signedIn: boolean = false) => StackNavigator(
  {
    [SIGNED_IN]: {
      screen: SignedIn,
      navigationOptions: {
        gesturesEnabled: false,
        header: null,
      },
    },
    [SIGNED_OUT]: {
      screen: SignedOut,
      navigationOptions: {
        gesturesEnabled: false,
        header: null,
      },
    },
  },
  {
    initialRouteName: signedIn ? SIGNED_IN : SIGNED_OUT,
  }
);

export default createRootNavigator;

Adding screenshots for clarity: As you can observe, the header content is not center aligned Height of the header is 64 Absolutely positioned header content is at the bottom

How can I center the header content and get rid of the unnecessary space from the top?

P.S I have already tried setting the height to headerStyle

like image 896
shet_tayyy Avatar asked Mar 14 '18 19:03

shet_tayyy


Video Answer


1 Answers

Try placing this code in your App.js file:

import { SafeAreaView } from "react-navigation";

if (Platform.OS === "android") {
  // removes extra space at top of header on android
  SafeAreaView.setStatusBarHeight(0);
}
like image 95
Steve Avatar answered Sep 17 '22 02:09

Steve