extension-safearea

Lime/OpenFL extension that adds support for getting safe area on iOS (to help support iPhone X)
https://github.com/HaxeExtension/extension-safearea

To install, run:

haxelib install extension-safearea 1.0.0 

See using Haxelib in Haxelib documentation for more information.

README.md

extension-safearea

An OpenFL extension that adds support for querying the screen safe area on iOS.

This allows you to avoid placing important elements behind the notch and rounded corners on the iPhone X, as well as any future devices.

Usage

Initialize extension-safearea:

SafeArea.init();

Note: SafeArea.init() should be called before any Event.RESIZE event listeners are added.

Query the unsafe border on each edge of the screen:

var paddingTop:Float = SafeArea.paddingTop;
var paddingBottom:Float = SafeArea.paddingBottom;
var paddingLeft:Float = SafeArea.paddingLeft;
var paddingRight:Float = SafeArea.paddingRight;

Query the safe area of the screen (the screen area inset by the padding):

var safeArea:Rectangle = SafeArea.safeArea;

Simple usage example

In this example, the screen safe area will be drawn.

import extension.safearea.SafeArea;
import openfl.display.Sprite;
import openfl.events.Event;

class SafeAreaExample extends Sprite
{
    public function new()
    {
        super();

        SafeArea.init();

        stage.addEventListener(Event.RESIZE, onResize);

        drawSafeArea();
    }

    function onResize(e:Event)
    {
        graphics.clear();

        drawSafeArea();
    }

    function drawSafeArea()
    {
        graphics.beginFill(0xFF0000, 0.5);

        graphics.drawRect(SafeArea.safeArea.x, SafeArea.safeArea.y, SafeArea.safeArea.width, SafeArea.safeArea.height);

        graphics.endFill();
    }
}

License

The MIT License (MIT) - LICENSE.md

Contributors
raggy
Version
1.0.0
Published
2 weeks ago
License
MIT

All libraries are free

Every month, more than thousand developers use haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on Github!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on Github