Skip to content

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

Closed

Description

@XxAdi101xX

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 apache/cordova-plugin-statusbar#112 but is still open at the time of writing.
Currently, I have a solution here -> apache/cordova-plugin-statusbar#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

Activity

  1. eyeswideopen commented on May 14, 2019

    @eyeswideopen

    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()

  2. tlatforlz commented on May 26, 2019

    @tlatforlz

    Is any thing else update? safe-area-inset just only work in iOS, and notch in android still problem.

  3. aayush-ios commented on Jun 28, 2019

    @aayush-ios

    Anyone find the solution? please share the solution in ionic 4 , notch display is not working

  4. Aarbel commented on Aug 28, 2019

    @Aarbel

    Looking also a solution to set safe-area-inset, cordova-plugin-android-notch is not fully doing the job, global css variable is not easy to maintain specificaly for android notch.

  5. added
    package: core
    type: bug
    on Oct 8, 2019
  6. pitis commented on May 23, 2020

    @pitis

    Yeah, the solution is to switch to React Native. I'm sick of Ionic problems. I've been strugglin with it for too long.

  7. Aarbel commented on May 24, 2020

    @Aarbel

    @pitis react native is unfortunately not ideal either.

  8. pitis commented on May 24, 2020

    @pitis

    @Aarbel that's also true, but I can show you a very big list of Ionic bugs I've found, that I'm sure if I started with RN i wouldn't have encountered, like this SafeAreaView problem, like the focusing on input in Modal making a glitch in the view. None have been addressed.

    Why isn't there something like SafeAreaView in Ionic? I've been struggling for a month now to get the paddings right in a project.

  9. coloz commented on May 25, 2020

    @coloz

    @pitis
    I used RN ,because of I'm sick of RN problems. I changed to ionic 😄

  10. liamdebeasi commented on Jun 12, 2020

    @liamdebeasi
    Contributor

    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 safe-area-inset is not respected for Android and only works on iOS #17927 (comment). 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!

  11. mightysloth commented on Jun 19, 2020

    @mightysloth

    Hi, I don't get why you closed this, I am bumping on that problem too. The solution given in #17927 (comment) doesn't work for me.

  12. liamdebeasi commented on Jun 19, 2020

    @liamdebeasi
    Contributor

    I closed this issue because the problem comes from the Android WebView code, not Ionic Framework. As a result, there is nothing for us to "fix" since it is not our bug.

    Regarding the workaround, I recommend creating a post on our forums: http://forum.ionicframework.com/. There are a lot of friendly people there who would be happy to help you out!

  13. ionitron-bot commented on Jul 19, 2020

    @ionitron-bot

    Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

  14. locked and limited conversation to collaborators on Jul 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: coretype: bug

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions