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.

SafeAreaView not working on Android. Giving wrong paddings

See original GitHub issue

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Environment: OS: macOS High Sierra 10.13.2 Node: 9.3.0 Yarn: 1.3.2 npm: 5.5.1 Watchman: 4.9.0 Xcode: Xcode 9.2 Build version 9C40b Android Studio: Not Found

Packages: (wanted => installed) react: 16.0.0 => 16.0.0 react-native: 0.51.0 => 0.51.0

Target Platform: Android (8.1.0) Pixel 2 XL

Steps to Reproduce

  1. Add view setup like this
<SafeAreaView style={{ flex: 1 }}>
    <View style={{ flex: 1 }} onLayout={this.onLayout} />
</SafeAreaView>
  1. Add onLayout function like this
onLayout = (event) => {
    const { y: top, height } = event.nativeEvent.layout
    const { height: screenHeight } = Dimensions.get('window')

    const safeAreaBottomPadding = screenHeight - height - top

    console.log(top, safeAreaBottomPadding) // prints 0, 27.9999.
}

Expected Behavior

Bottom padding should be calculated 0.

Actual Behavior

The bottom padding comes out 27.9999 which is half the size of bottom soft navigation bar so it does not make sense. (Top status bar seems about 28 pixels, but y gets value of 0).

Reproducible Demo

(Paste the link to an example project and exact instructions to reproduce the issue.)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:20 (3 by maintainers)

github_iconTop GitHub Comments

16reactions
sgtpepper43commented, Nov 6, 2018

There’s a new api for android devices called DisplayCutout that can be used for dealing with notches. We should consider using this with SafeAreaView. I would post this in a new issue or feature request but I honestly cannot figure out where I’m supposed to do that.

8reactions
burkeshartsiscommented, Feb 18, 2019

Currently SafeAreaView on android just returns a View 😢

~~https://github.com/facebook/react-native/blob/master/Libraries/Components/SafeAreaView/SafeAreaView.android.js~~

Update: Still just returns a view on Android but everything lives in one component now.

https://github.com/facebook/react-native/blob/master/Libraries/Components/SafeAreaView/SafeAreaView.js#L37

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use SafeAreaView for Android notch devices?
The SafeAreaView is a solution for the iPhone X but for Android, it seems there is no solution. How to solve this kind...
Read more >
Supporting safe areas | React Navigation
While React Native exports a SafeAreaView component, it has some inherent issues, i.e. if a screen containing safe area is animating, it causes...
Read more >
SafeAreaView - React Native
SafeAreaView renders nested content and automatically applies padding to reflect the portion of the view that is not covered by navigation ...
Read more >
How to Use Safe Area Context in React Native Apps to Avoid ...
The SafeAreaView acts like a regular View component from React Native and includes additional padding to position the content below the notch or ......
Read more >
SafeAreaContext - Expo Documentation
Android Device, Android Emulator, iOS Device, iOS Simulator, Web ... SafeAreaView is a regular View component with the safe area edges applied 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