safeAreaInsets (of Display)

Hi, any reason why this should change during the execution of an app? Figured it should be constant.

If not, what can cause this to change?


I can think of a case in which it would make sense for the safeAreaInsets to change during runtime: when on Android a translucent theme is used.

On Android there’s an option to set the navigation bar on the bottom of the screen to either be displayed permanently (“buttons”) or remain hidden (“swipe gestures”).

If an app uses a normal (opaque) theme, then the user area will be different in both cases and the safeAreaInsets will reflect only the cutout on the top of the screen.

But if the navigation bar is translucent, then the user area will remain the same in both cases as it reflects the total area onto which the app can draw its background.

In this case, I think the safeAreaInsets should indicate the size of the navigation bar on the bottom of the screen, when it is displayed, so the gui elements are not drawn on that area.

This is not implemented but I think it should be. Otherwise how can one deal with this situation in which the user can either hide the navigation bar or display it, but the background (userArea) remains constant?


hi, thx, interesting.

This is definitely not happening though, something is changing the value of top for no apparent reason.

Are you seeing this on Android?

I am struggling to understand how the userArea and safeAreaInsets are implemented on Android, even when a normal non-translucent theme is used. The safeAreaInsets change with the orientation, but not in a way which makes sense.

These are my tests using the standard no-titlebar theme and not using kiosk mode (Android 11, Galaxy A22):

Orientation: Upright
Total area: 0 0 384 857
User area: 0 23 384 786
Safe area insets: 23 0 0 0 (correct, camera notch is on the top)

Orientation: Rotated Clockwise
Total area: 0 0 857 384
User area: 0 24 786 360 (should be 0 24 810 360, since the status bar is now on the top)
Safe area insets: 0 0 0 0 (should be 0 23 0 0, notch is on the left)

Orientation: Rotated Anti-clockwise
Total area: 0 0 857 384
User area: 0 24 786 360 (should be 0 24 810 360 or 48 24 810 360)
Safe area insets: 0 0 0 0 (should be 0 0 0 23, notch is on the right)

(Sorry to hijack your thread, hope this stuff is relevant!)

As a result of this the demorunner draws some areas incorrectly.

Without using kiosk mode (which is what most apps on Android use and what users expect):

Hi, no, I’m not on android, and I’m not doing any rotations or resizing or anything.

I’m just noticing that on some refreshes, the safeAreaInsets has changed and I’m trying to understand whether this is a bug or whether there is a legitimate reason for this happening.

It’s a good question, I can’t think of a reason for that to happen.