cordova-plugin-android-notch
This plugin allows to query android notch insets.
For iOs, the insets are available as constant() and env() variables. However this doesn't work on android 9, which is where this plugin can help.
Usage
windowAndroidNotch); windowAndroidNotch); // There is also getInsetRight, getInsetBottom, getInsetLeft
If you want to use those variables in css, here's a possibility:
// Call this on resize or orientationchange, but *after* the deviceready event { if windowAndroidNotch const style = documentdocumentElementstyle; // Apply insets as css variables windowAndroidNotch; windowAndroidNotch; windowAndroidNotch; windowAndroidNotch; }
Then in your css:
/* Use it with var(--notch-inset-top) now, for example: */
Compatibility
This plugin works on all android versions, but we can only detect notches starting from Android 9. They have been available on Android 8 as vendor specific additions, but I haven't figured how to detect those yet. Feel free to make a PR!