I encounter an issue with the env variable safe-area-inset-top. Actually, the value of this variable in defined to 0px when I open the application and so, the content on the top of the app overlaps the camera notch and the statusbar.
A strange thing appears when I open and close a browser alert (window.alert('something')). After the close of this alert, the variable safe-area-inset-top is defined and so, the space is correctly present on the top. I suppose that this is because the viewport is recalculated but I don’t arrive to force the same behavior without using an alert.
It works fine on IOS and I suppose maybe on other devices with Android. The device with which I am having this problem is a Galaxy A51 with Android 13 (One UI 5.1).
My version of Ionic is 7.0.4 and my version of Capacitor is 5.0.3.
Sorry for my late reply.
No, I didn’t find a real/good solution for this bug but, I defined a CSS rule to ensure the space for Android.
Something like this:
--sat: env(safe-area-inset-top);
.header {
padding-top: max(30px, var(--sat)); // Define a minimum safe space by default
html.plt-ios & {
padding-top: var(--sat); // Use the detected safe-space for IOS because I always get a good value
}
}
This isn’t entirely correct because it will overwrite the default value set based on the device (if any) and the safe-area-top is potentially different on devices.
A better approach is to set a fallback value when no value is set by using the function max (to ensure using the bigger value: max(30px, var(--ion-safe-area-top));
But the best approach still be the real support/definition of the safe-area-inset-top on all devices but It depends on the manufacturer of each device.
Also, to solve the Android issue of wrong value at the init of the webview, we can use the package import { SafeArea } from 'capacitor-plugin-safe-area'; like this:
N.B: The fallback value of the “var” function is a good idea but the fallback will be used only if the variable does not exists or in this case, the variable exists but the value is sometime wrong (equal to 0).