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