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.

Modal component on Android is not underneath a translucent StatusBar, inconsistent with iOS

See original GitHub issue

When you set translucent to true in a StatusBar component in Android, then open a Modal component, the Modal children are not underneath the status bar like the main content. This is inconsistent to the behavior on iOS where Modal children are underneath the status bar. Therefore as a workaround you need to add a style that looks something like this to the body of a modal:

marginTop: Platform.OS === 'android' ? -StatusBar.currentHeight : 0
  • Minimal code snippet: https://rnplay.org/apps/0ppHZw
  • Version of React Native is 0.29.0
  • The error only occurs in Android (but if it occurred in both would it be a feature and not a bug?)
  • I’m developing on a Mac.

…and here is the code snippet copy/pasted from RNPlay (works on both iOS and Android):

import React, { Component } from 'react'
import { AppRegistry, View, Text, TouchableOpacity, StatusBar, Modal } from 'react-native'

class SampleApp extends Component {
  state = {
    isModalOpen: false,
  }

  handleModalOpen = () => this.setState({ isModalOpen: true })
  handleModalClose = () => this.setState({ isModalOpen: false })

  render () {
    return (
      <View>
        <StatusBar
            translucent
            barStyle="light-content"
            backgroundColor="rgba(0, 0, 0, 0.2)"
        />
        <Text>I’m underneath the status bar</Text>
        <TouchableOpacity onPress={this.handleModalOpen}>
            <Text style={{ marginTop: 50 }}>Press me to open the modal</Text>
        </TouchableOpacity>
        <Modal
            animationType="slide"
              transparent={false}
            visible={this.state.isModalOpen}
            onRequestClose={this.handleModalClose}
        >
            <View style={{ flex: 1, backgroundColor: 'white' }}>
            <Text>I should be underneath the status bar</Text>
            <TouchableOpacity onPress={this.handleModalClose}>
              <Text style={{ marginTop: 50 }}>Press me to close the modal</Text>
            </TouchableOpacity>
            </View>
          </Modal>
      </View>
    )
  }
}

AppRegistry.registerComponent('SampleApp', () => SampleApp)

iOS Modal closed

screen shot 2016-07-29 at 2 03 49 pm

iOS Modal opened

screen shot 2016-07-29 at 2 04 04 pm

Android Modal closed

screen shot 2016-07-29 at 2 04 22 pm

Android Modal opened (ERROR HERE)

screen shot 2016-07-29 at 2 04 32 pm

Issue Analytics

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

github_iconTop GitHub Comments

8reactions
nascodecommented, Apr 6, 2017

0.43.0 here. I can confirm that there is still a bug when using modal with translucent status bar on android

0reactions
lihxhitcommented, Jul 1, 2018

+1

There seems to be a pr which deal with the hidden statusbar but we need a translucent StatusBar

Read more comments on GitHub >

github_iconTop Results From Across the Web

Modal component on Android is not underneath a translucent ...
Modal component on Android is not underneath a translucent StatusBar, inconsistent with iOS. Facebook Bot.
Read more >
React Native Modal is not drawn below the StatusBar on ...
In React Native (With EXPO), I'm showing a Modal. The Modal gets drawn behind the StatusBar in iOS but it's not happening on...
Read more >
Bountysource
Modal component on Android is not underneath a translucent StatusBar, inconsistent with iOS.
Read more >
Customize the Application Status Bar
The app status bar in mobile apps is black by default and it's always visible. This behavior is customizable without using any plugin...
Read more >
Supporting safe areas | React Navigation
Status bar overlay; Home activity indicator on iOS; Navigation bar on Android. The area not overlapped by such items is referred to as...
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