-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android 11 css safe-area-insets not applied #1465
Comments
Can you reproduce (including it working on cordova-android@10) this on an emulator or on a device that simulates notches (using the Developer Options)? In my experience, CSS safe area insets never properly worked on android, but I also don't have a physical device with notches either. |
Yes: I used the Developer Option to simulate a notch (double cutout) Result with android-10.1.1: (the black bar is the notch space) Result with android-11.0.0: The notch / black bar is not considered - the css safe-area styles don't seem to get applied I didn't change anything except changing the platforms from |
Sorry, but any update on this? Anything else I could try? |
Sorry, I haven't had a chance to look at this myself. I'm not really sure at this time. I can say that Cordova doesn't implement browser features (Cordova isn't the browser, it's just a packaging tool providing resources to be used by the system's webview). So it's really strange see a browser feature suddenly not work between two different cordova-android versions and it's definitely not clear what might be the cause of it. If someone wants to poke around, the commits since If I were to take a wild guess, cordova-android 11 implements the new splashscreen API that Android offers, for API 32 support. This involves making changes to the app theme. You could try forking cordova-android and reverting this commit to see if it changes anything. Hopefully it won't completely break the build... it may cause issues related to the splashscreen, but if it fixes the safe area inset, then we know it's something within this splashscreen PR that is causing the issue. |
While further exploring this issue i found this resource: https://developer.android.com/guide/topics/display-cutout. The way the cutout behaves, can be defined in manifest inside <style>. So i tried adding
to file As to why the default behaviour changed, i don't know. Maybe because we target higher API version now. Or because theme on main activity was changed to Since i need a quick solution to this i will be creating a after_platform_add hook in my project that will create a Maybe in the future this could be controlled with a setting in config.xml :) |
I have the same issue, but after forcing a reload, The above solutions I would prefer the "CUTOUT_MODE_SHORT_EDGES" but without forcing a reload. Any update? |
Still no update? |
I have the solution!
This will first calculate the For a quick test, add the following to
|
Looks like we need to wait for Android to support the safe-area. See this Chromium Bug. Thanks @nijakobius for providing a workaround. We could add this code with a note about this issue to the README files under the Android quirks section. What do you think? |
Looks like the latest Android System WebView (107.0.5304.105) solved the problem. I've checked with 108.* Beta and 109.* Dev builds also, they work well |
If we add a note, I'd rather just link to the comment using #1465 (comment) than have code in-pace I think. In effort to keep the README docs clean/concise. Since it was determine that this was a system webview issue, I'll be closing this issue. Should be resolved if the device has version |
The issue still reproduces for me on a Nokia 7.1 with Android System WebView 107.0.5304.141. This Chromium issue is still open and appears to be the underlying issue. I would not expect this to be fixed until that issue is closed. It would be nice if Cordova could provide a built-in workaround until then though. |
The issue reproduces for Samsung Galaxy S21, webview 108.0.5359.79 #1465 (comment) doesn't always work: my app is landscape. #1465 (comment) works for me. It doesn't have to be a script. After themes_v27.xml is created, the following works in config.xml, android section:
I think it's a decent fix because the behavior is consistent with previous versions. And it can always be improved once the upstream Chromium bug is fixed. |
I think using From my understanding based on the Android Docs, We could add a preference to configure this, but if a workaround can be done simply by providing a resource-file, I think I'd prefer documenting that approach rather than adding a feature option that we would have to maintain thereafter, especially since this feature is just for a workaround to an upstream chromium bug. @cxcxcxcx If you could provide a full example of the workaround including the contents of |
For my device, it's black, the same color as the phone edge. I didn't notice it until I upgraded to cordova-android 11. It's probably a fallback mechanism that phone manufactuers considered to support older apps.
Yeah, it's weird to workaround an upstream bug. However, because cordova is largely about enabling HTML5 on native apps, the upstream bug sounds a deal-breaker: almost all apps will suffer, but developers may not realize just because they don't have test devices with cutouts. Forcing not using the cutout space is not ideal, but it's reverting to the cordova-android 10 behavior. Power users can still customize using hooks, and the default behavior will be decent.
I cloned the
|
Ah yah, if you're cloning the theme... that kinda makes me want to add a preference. That workaround creates a high risk of breakage since it depends on you kinda re-implementing things required for Cordova, which if Cordova changes the splashscreen things, it will end up likely breaking. So a preference will allow Cordova to actually manage it in a way that you don't need to clone. I'll re-open this issue. I'm hoping to find at least some time over the xmas break to work on some cordova stuff. I'll see if I can find a way to make the change so that it produces both the existing theme, and a |
I had the same problem on Android 13 phones but I was able to solve the problem by deleting the plugin [email protected] and installing the plugin [email protected] and to be ok on android 12 or lower, I also put in .css html.device-android .statusbar, I know "safe-area-inset-top" doesn't work for Android, but I set it to override for Android 12 or lower, which is set by default! That's how it works for me, ok :) I use cordova 11.0.0, cordova android 11.0.0 and framework7 with vue. |
Any updates about the preference? |
Upstream Android WebView Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1094366 |
Moving this from the 11.0.1 milestone to 12.0.0 milestone because master already has the major version bump, however unsure if the workaround noted in #1465 (comment) will make it. I feel it may be better to document the quirk and provide instructions on how to implement the workaround solution instead. |
The current workaround I'm using is creating a hook named: "windowLayoutInDisplayCutoutMode". Here's the code for the hook: const fs = require('fs');
const path = require("path");
module.exports = function (ctx) {
const xml = `<?xml version='1.0' encoding='utf-8'?>
<resources>
<style name="Theme.App.SplashScreen" parent="Theme.SplashScreen.IconBackground">
<item name="windowSplashScreenBackground">@color/cdv_splashscreen_background</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_cdv_splashscreen</item>
<item name="windowSplashScreenAnimationDuration">200</item>
<item name="postSplashScreenTheme">@style/Theme.AppCompat.NoActionBar</item>
<item name="android:windowLayoutInDisplayCutoutMode">never</item>
</style>
</resources>`
const themesXML = path.join(ctx.opts.projectRoot, 'platforms/android/app/src/main/res/values/themes.xml');
fs.writeFileSync(themesXML, xml);
}; And then I imported the hook in the projects config.xml: <platform name="android">
<hook type="after_platform_add" src="hooks/android/windowLayoutInDisplayCutoutMode.js" />
</platform> The settings probably won't work for everyone, the best way would be to parse the XML and just insert the tag into it. |
Is there any existing Cordova plugin that can work around this in the mean time? Perhaps someone who has a good workaround could publish one? I'd much appreciate it! |
I just open sourced our internal package we are using @totalpave/cordova-plugin-insets. It can be installed by doing totalpave.Insets.addListener((inset) => {
/* inset = {
top: number;
right: number;
bottom: number;
left: number;
};
*/
}) The plugin keeps track of the inset regardless of attached listeners. So you can also poll the current known inset information via The plugin provides an Android implementation only. So if you support multiple platforms, you need to guard it. Will be publishing to official NPM registry soon. The plugin isn't perfect and currently does produce an issue on app launch where the bottom inset is higher than expected. It's also not yet used in any of our production apps. This plugin aims just to provide the Inset information. It's up to you on how you want to consume it. For example, if you want to make this information available to CSS, then you could programmatically set the CSS variables on the listener (See W3Schools example) Because I don't foresee a reasonable fix (I believe it is an Android Webview bug), I'll be removing this from the 12.x milestone. EDIT: The above example for the plugin refers to an older version, but the latest version does have docs |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Is there anyway then to use the Capacitor plugin for safe-area, in a Cordova Ionic application? Are they compatible with each other? |
FWIW we use |
Bug Report
Problem
cordova create hello com.example.hello HelloWorld
)=> The safe-area is considered.
cordova platform remove android
cordova platform add [email protected]
cordova run android
=> The safe-area is not considered anymore
Only change I made in the
config.xml
:What is expected to happen?
Using css padding safe-area-insets should add a safe-area padding
What does actually happen?
The padding for the safe-area is not added when using
[email protected]
Information
Command or Code
Environment, Platform, Device
Version information
cordova: 11.0.0
npm 8.11.0
Checklist
The text was updated successfully, but these errors were encountered: