SafeAreaView not working on Android. Giving wrong paddings
See original GitHub issueIs 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
- Add view setup like this
<SafeAreaView style={{ flex: 1 }}>
<View style={{ flex: 1 }} onLayout={this.onLayout} />
</SafeAreaView>
- 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:
- Created 6 years ago
- Reactions:4
- Comments:20 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.Currently
SafeAreaView
on android just returns aView
😢~~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