question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Drawer hideStatusBar breaks SafeAreaView on repeated navigation with screens enabled

See original GitHub issue

Description

When you have a Drawer navigation with hideStatusBar prop and screens enabled, repeated navigation to the same screen is setting SaveAreaView top inset to 0.

Screenshots

Steps To Reproduce

  1. open app, see that the green background does not cover status bar
  2. go to Notifications, status bar is not covered
  3. open drawer again and dismiss it or go to notifications again
  4. status bar is covered with green

Expected behavior

  1. status bar should not be covered

Snack or minimal code example

import 'react-native-gesture-handler';
import {createDrawerNavigator} from '@react-navigation/drawer';
import {NavigationContainer} from '@react-navigation/native';
import {View, Text, Button} from 'react-native';
import React, {StrictMode} from 'react';
import {SafeAreaProvider, SafeAreaView} from 'react-native-safe-area-context';
import {enableScreens} from 'react-native-screens';

enableScreens();

const Drawer = createDrawerNavigator();

function Home({navigation}) {
  return (
    <SafeAreaView style={{flex: 1}}>
      <View
        style={{
          backgroundColor: 'green',
          flex: 1,
          alignItems: 'center',
          justifyContent: 'center',
        }}>
        <Text>Home</Text>
        <Button
          onPress={() => {
            navigation.openDrawer();
          }}
          title="open drawer"
        />
      </View>
    </SafeAreaView>
  );
}

function Notifications({navigation}) {
  return (
    <SafeAreaView style={{flex: 1}}>
      <View
        style={{
          backgroundColor: 'green',
          flex: 1,
          alignItems: 'center',
          justifyContent: 'center',
        }}>
        <Text>Notifications</Text>
        <Button
          onPress={() => {
            navigation.openDrawer();
          }}
          title="open drawer"
        />
      </View>
    </SafeAreaView>
  );
}

function App() {
  return (
    <StrictMode>
      <SafeAreaProvider>
        <NavigationContainer>
          <Drawer.Navigator initialRouteName="Home" hideStatusBar>
            <Drawer.Screen name="Home" component={Home} />
            <Drawer.Screen name="Notifications" component={Notifications} />
          </Drawer.Navigator>
        </NavigationContainer>
      </SafeAreaProvider>
    </StrictMode>
  );
}

export default App;

Package versions

  "@react-navigation/drawer": "^5.12.3",
  "@react-navigation/native": "^5.9.2",
  "react": "16.13.1",
  "react-native": "0.63.4",
  "react-native-gesture-handler": "^1.10.1",
  "react-native-reanimated": "^1.13.2",
  "react-native-safe-area-context": "^3.1.9",
"react-native-screens": "^2.17.1"

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
somebody32commented, Feb 23, 2021

Thanks a lot! Closing it then as soon as this is expected behavior

0reactions
WoLewickicommented, Feb 23, 2021

I am not too keen with the implementation of the library, but it may be related to usage of ViewControllers for each of the screens in the navigator, when using react-native-screens. Each screen perhaps requires the SafeAreaProvider to be under it. Maybe @janicduplessis could elaborate more on this. Can I help you any more regarding this issue or can we close it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Different status bar configuration based on route
Different status bar configuration based on route. If you don't have a navigation header, or your navigation header changes color based on the...
Read more >
how to hide a screen from drawer in react navigation 5
1. function DrawerNavigator() { ; 2. return ( ; 3. <NavigationContainer> ; 4. <Drawer.Navigator ; 5. initialRouteName="Home".
Read more >
How to use SafeAreaView for Android notch devices?
Do something like import { StyleSheet, Platform, StatusBar } from "react-native"; export default StyleSheet.create({ AndroidSafeArea: ...
Read more >
How to Handle Safe Area Insets for iPhone X, iPad X, Android P
Devices with Edge-to-Edge Screens and a Notch or Display Cutout ... adds tab navigation (iOS) or drawer menu (Android) Navigation {
Read more >
Combining Drawer, Tab and Stack navigators in React ...
We will also implement each of the routes as a Stack Navigator, since we now that, for instance, the Book flow will contain...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found