Safe area extension

Hi all!

I hacked together a minimal library that will resize the UIView (with constraints) based on “safe area” on iOS. This should be a quick thing to add to a game/app, until you have added current GUI layouts.

The current state is very untested, so use at your own risk. :slight_smile: (Also, I haven’t had time to create community page for it yet.)

Download and URL

The source can be found here: https://github.com/defold/extension-safearea
And the library can be added to your project with this URL: https://github.com/defold/extension-safearea/archive/master.zip

Examples

The red color indicates safe area (ie the game being rendered), the yellow is the “background” color outside the safe area.

Example portrait:

Example landscape:

9 Likes

Important updates for the extension:

  • New method safearea.get_insets() that returns the amount of “unsafe” space against each edge of the screen, in pixels (thanks @dapetcu21 !)
  • safearea.get_insets()now works for Android as well

Updated doc is available here: https://github.com/defold/extension-safearea/blob/master/docs/index.md

5 Likes

version 1.3 released:

  • Now get_insets() method returns status value
local insets, status = safearea.get_insets()

-- The amount of "unsafe" space against each edge of the screen, in pixels
print(insets.top, insets.right, insets.bottom, insets.left)

-- Status is one of the following values:
-- safearea.STATUS_OK - value is avaliable and valid, you may fully trust it.
-- safearea.STATUS_NOT_AVAILABLE - functionality isn't available on this platform or OS version. Values will be 0
-- safearea.STATUS_NOT_READY_YET - values aren't ready yet. Depends on platform and OS it may take a while (usually up to 200ms) to be ready, check later. Values will be 0
4 Likes

The value I get for insets.top is twice as big as the notch itself.
It feels like it’s not counting the the status bar (i’m using immersive mode).

If i divide the value by 2 I get the exact size of the notch, but I don’t know the reason behind this.

Is that a bug from the library or am I misusing it?

Interesting. What is the size of your display in game project? And what is the size of your phone’s screen?

Game project is 720x1280
currently testing with android device 1080x1920

Please create a ticket in the repo and we’ll take a look!

Is it possible to have a game Android where we display the game below the status bar?

I updated the android manifest with
android:theme="@android:style/Theme.NoTitleBar"

so the status bar is showing correctly.

My problem is the game starts drawing BEHIND the status bar. Is there anyway too avoid that? (it would probably fix the notch issue I’m having).

Take a look these options in Android section

I checked the “Display Cutout” on/off but it doesn’t make any difference

This is my UI in the editor:

(the top bottom has pivot as NORTH.

My manifest is android:theme="@android:style/Theme.NoTitleBar"

Wether I check the “Display Cutout” or not, I get:

as you can see the top element is behind the status bar