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.

safe-area-inset is not respected for Android and only works on iOS

See original GitHub issue

Bug Report

Ionic version:

[x] 4.x

Current behavior:

The safe-area-inset-top is not respected on android devices so even with a notch at the top, there is no padding added. Expected behavior:

The safe-area should be respected similar to what’s happening on iOS

Steps to reproduce:

Open the ionic conference app with a notched android phone, or on an android emulator running Android P or above so that a notch can be added programmatically to test. Then add this.statusBar.overlaysWebView(true); in the initializeApp() function located in app.components.ts before running the app.

Screen Shot 2019-04-01 at 2 47 27 PM Screen Shot 2019-04-01 at 2 46 48 PM

But this is handled fine on iOS:

Screen Shot 2019-04-01 at 2 49 27 PM

Other information:

This issue was brought up in the cordova-plugin-statusbar repository https://github.com/apache/cordova-plugin-statusbar/issues/112 but is still open at the time of writing. Currently, I have a solution here -> https://github.com/apache/cordova-plugin-statusbar/pull/134 (see feature/addGetStatusBarHeightMethod) which will introduce to a way to obtain the height of the status bar through a service call. However, it would be ideal if the safe-area-inset can be enhanced to also work for Android devices

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:12
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
eyeswideopencommented, May 14, 2019

I’m having the same issue and temporarily resolved it with:

  • installing cordova-plugin-android-notch (github repo)
  • setting the missing ‘–ion-safe-area-top’ css var for android via
declare var window: any;

if (window.AndroidNotch) {
        const style = document.documentElement.style;

        window.AndroidNotch.getInsetTop(px => {
          style.setProperty('--ion-safe-area-top', px + 'px');
        }, (err) => console.error('Failed to get insets top:', err));
}

in the initializeApp() in app.component.ts inside a platform.ready()

1reaction
liamdebeasicommented, Jun 12, 2020

Thanks for the issue. I am going to close this as this is not a bug in Ionic Framework.

Ionic Framework is functioning as intended with regards to utilizing the safe-area-inset variables. However, the Chromium webview found on Android is not properly setting the safe-area-inset values. As a result, all of the values are initialized to 0px. This results in the behavior you are experiencing.

There is nothing we can fix right now, as the bug is in the webview not Ionic Framework. I have reported this bug to the Chromium team: https://bugs.chromium.org/p/chromium/issues/detail?id=1094366.

As a temporary workaround, I recommend one of the following routes:

  1. Do not use overlaysWebView(true) for now. (Not ideal, I realize.)

  2. Try using the plugin suggested in https://github.com/ionic-team/ionic/issues/17927#issuecomment-492198561. It sounds like this is not a perfect solution, but for simple use cases this may get the job done. You could use this to set the --ion-safe-area-top CSS Variable. Please note that this should be done at runtime.

Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Handle Safe Area Insets for iPhone X, iPad X, Android P
You then have two options to work with the safe area: Configure only certain content items within the Page to align with the...
Read more >
env(safe-area-inset-top) not working on Android Pie + ...
I have a fullscreen cordova app, I used to use the css below for iPhone X's notch, padding ...
Read more >
Supporting safe areas | React Navigation
Home activity indicator on iOS; Navigation bar on Android. The area not overlapped by such items is referred to as "safe area". We...
Read more >
1094366 - safe-area-inset-* values are always 0px in webview
Run `npx cap open android` to open the Android app in Android Studio. ... but I am not sure if this ever worked...
Read more >
Extend a footer outside the Safe Area with SwiftUI
If you fully respect the safe area you will see a different colored background behind the home indicator. ... This solution works on...
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