capacitor: bug: SafeArea for iphoneX in notch

Bug Report

Capacitor Version

npx cap doctor output:

πŸ’Š Capacitor Doctor πŸ’Š

Latest Dependencies:

@capacitor/cli: 1.3.0

@capacitor/core: 1.3.0

@capacitor/android: 1.3.0

@capacitor/ios: 1.3.0

Installed Dependencies:

@capacitor/cli 1.3.0

@capacitor/core 1.3.0

@capacitor/android 1.3.0

@capacitor/ios 1.3.0

Affected Platform(s)

  • Android
  • iOS
  • Electron
  • Web

Current Behavior

Currently in iphone X there is no safe area for the webview, in order to see the content correctly and not overlap the notification bar.

Expected Behavior

It is desired that there is a safearea for the webview on an iPhone X, so that the content is viewed correctly and does not overlap the notification bar.

Sample Code or Sample Application Repo

Reproduction Steps

Other Technical Details

npm --version output: 6.9.0

node --version output: v10.16.3

pod --version output (iOS issues only): 1.8.4

Other Information

Captura de Pantalla 2019-10-26 a la(s) 14 08 24

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (1 by maintainers)

Most upvoted comments

Yes, this is web/css concern, not a Capacitor one. For what it’s worth, Ionic Framework handles this for you.

Forget it, I was missing the viewport-fit=cover in the meta tag. Thanks!

You should use CSS for this: https://webkit.org/blog/7929/designing-websites-for-iphone-x/

If you need to know the safe area insets in JS, you can do this using this library: https://github.com/zhetengbiji/safeAreaInsets

I am doing this and it works perfectly.

webview inside capacitor is returning 0 for env(safe-area-inset-top) in an iPhone X

Unfortunately it does not work with android yet.

@mcqj capacitor does not provide you with those values as it’s not needed - the browser that your app runs inside already has this information and you can access it using css with or without js (see links I posted previously).

FWIW, I recently had to implement this as well. The approach I took that worked was:

  1. Detect the type of device using the Device API
  2. Using JavaScript, fetch and match screen viewport sizes to the known sizes for iPhones/iPads with notches
  3. If a match is found, append a css class to the body tag (ex: β€œios”, β€œiphone”, β€œnotch”, etc.)
  4. Create CSS styles that modify based on the platform-specific classes you create.