Safe Area data seems wrong as of Corona 2017.3173

As of Corona 2017.3173, it appears that my safe area information has changed as from Corona 2017.3173 (even on iPhone 6). It’s been screwing with a lot of my display.

Corona 2017.3172 - iPhone 6 Simulator :

display.screenOriginX: -44.5
display.screenOriginY: -0
display.safeScreenOriginX: -44.5
display.safeScreenOriginY: 0
display.safeActualContentWidth: 569.17333984375
display.safeActualContentHeight: 320

Corona 2017.3173 - iPhone 6 Simulator:
display.screenOriginX: -44.5
display.screenOriginY: -0
display.safeScreenOriginX: -44.5
display.safeScreenOriginY: 17.066667556763
display.safeActualContentWidth: 569.17333984375
display.safeActualContentHeight: 302.9333190918

I’ve attached my test to the posting (safe area test.zip).

Is this a bug or normal behavior?

There were changes to the safe zone calculations in 3173, so I would expect some differences between 3172 and 3173.

Rob

We are using Corona 2017.3179 and are seeing different values for OriginY.

IPAD (in simulator)

display.screenOriginY: -0

display.safeScreenOriginY: 9.375

IPHONE 6 (in simulator)

display.screenOriginY:-44.5

display.safeScreenOriginY:-27.433332443237

This occurs in both the simulator and IOS device builds.  

Is this correct?  possibly moving the safe space to not include the IOS status bar at the top of the screen?  Our app has the status bar disabled. 

It seems like the OriginY should be the same as the safeOriginY with no status bar and not on the iphone X

Of course, they are going to be different.  Depending on your config.lua’s aspect ratio and because an iPad and iPhone 6 are radically different aspect ratios (iPad 4:3 or 1.3333333333:1 vs. an iPhone 5, 6, 7, 8’s 16:9 or 1.7777778:1) your defined content area, if you’re centering it is going to have extra space.

Now the value of 9.375 for the status bar vs. 17.433 seems a bit of an oddity.

I can ask engineering to consider checking the status of the status bar in the calculations, but I can predict their answer. You know if you’re using a status bar or not. Use the safe area if you are, the normal values if you are not.  

It only becomes an issue on iPhone X or Android with sticky immersive button bars.

Rob

Hey Rob… thanks for the response.

I definitely understand that the iphone and ipad will have different values.  That makes total sense.  I was just listing both as examples.

Lets take the regular iphone 6 as an example…  From your documentation it sounded like the display.safeScreenOriginY would be the same as display.screenOriginY.   There is no notch like an iphone X and the status bar is hidden. 

It seems like the top of the screen should be included in the safe area but it is not.  Safe area starts below the top of the screen (screenOriginY)  This throws off our alignment. 

IPHONE 6 (in simulator)

display.screenOriginY:-44.5

display.safeScreenOriginY:-27.433332443237

Using the safeArea setting works great for iphone X but but leaves a gap at top on other iphones.  I have included a screen shot of the app in simulator.  The iphone 6 image on the left has a white gap at the top.   We are using the display.safeScreenOriginY as the top of the orange bar on both screen shots. 

I did not want to have to detect an iphone X and special case it.   Right now the only way to get it to work would be to use the safeScreenOriginY on iphone X and the screenOrigniY on other devices.

I could be thinking about this wrong… so please let me.  Appreciate your help!!!

Hello. We decided to follow Apple’s guides for safe area insets. Basically, if you render content inside safe area it means that it will not be obscured by bezels or status bars, or any system UIs on android. This is how API worked for a while now. Most of the difference in Corona 3173 that Simulators now follow same rules as devices did before.

I understand that you have non-game app in which it is not appropriate to hide status bar. but if you do, you’ll see that on all devices but iPhone X safe areas would be same as content areas.

Basically, you should fill whole Content Area, but position important bits inside Safe Area. You can stretch your title bar background from “contentOriginY” to “safeScreenOriginY+titleBarIconsHeight”, and render your title bar icons centred in safeScreenOriginY+titleBarIconsHeight*0.5.

This way you would always have nice looking title bar icons below iPhone X bezels or ordinary iPhone’s status bars, or just on top of the screen if status bar is off. 

I think code with some pictures would be easiest explanation here. So, I made a snippet. It draws titlebar, and 5 round buttons in the beginning of it. Titlebar has grey background.

[lua]

display.setStatusBar( display.HiddenStatusBar )

– comment out next line to hide status bar

display.setStatusBar( display.DarkTransparentStatusBar )

local titleBarHeight = 30

– it is easier just to create/destroy elements when device is rotated in such simple case

– so we’ll jsut put all elements in group, and re-create it every time we need to resize

local group = display.newGroup()

local function reCreateElements ( )

    – re-create group with titlebar elements

    group:removeSelf( )

    group = display.newGroup()

    – creating grey titlebar background

    – it starts from screen origin, and goes down from safe area beginning to titleBarHeight

    local x0 = display.screenOriginX – left of the screen

    local y0 = display.screenOriginY – top of the screen

    local x1 = display.screenOriginX + display.actualContentWidth – right of the screen

    local y1 = display.safeScreenOriginY + titleBarHeight – space for title bar after safe area

    local titleBarBackground = display.newRect(group, (x0+x1)*0.5, (y0+y1)*0.5, x1-x0, y1-y0)

    titleBarBackground:setFillColor( 0.9 )

    local buttonsY = display.safeScreenOriginY + 0.5*titleBarHeight  – buttons are centred in the middle of status bar

    local buttonsX = display.safeScreenOriginX  – button start from left of status bar

    – create 5 buttons

    for i = 0, 4 do

        local r = 0.5*titleBarHeight  – radius

        local x = buttonsX + (i*2+1)*r  – each button has width 2*radius, plus one radius offset for first button

        local y = buttonsY

        local button = display.newCircle(group, x,y, r)

        button:setFillColor( math.random()*0.5+0.2,math.random()*0.5+0.2,math.random()*0.5+0.2 )

    end 

    – -- this just to demonstrate area one has to use to draw actual title bar content

    – local areaWhereActualTitleBarContentIs = display.newRect(group, display.safeScreenOriginX,display.safeScreenOriginY, display.safeActualContentWidth, titleBarHeight)

    – areaWhereActualTitleBarContentIs.anchorX, areaWhereActualTitleBarContentIs.anchorY = 0, 0

    – areaWhereActualTitleBarContentIs:setFillColor( 0,0,0,0.1 )

end

reCreateElements()

– when device is rotated, just re-create all elements

Runtime:addEventListener( “resize”, reCreateElements )

[/lua]

Here’s some screenshots:

iPhone 6 without status bar

kYUqccL.png

iPhone 6 with status bar

JAoopvR.png

iPhone X portrait:

RLQ2Lqi.png

iPhone X landscape:

eCw7tSS.png

As you can see, using safe area + content area can make your app adaptable to pretty much any screen configuration…

Thanks for the sample. It was helpful!!!  Think we figured out our problem.  We were initializing a few things before setting …display.setStatusBar( display.HiddenStatusBar )…This was causing the our calculations/screen positioning to be incorrect.   We have it working better now!

There were changes to the safe zone calculations in 3173, so I would expect some differences between 3172 and 3173.

Rob

We are using Corona 2017.3179 and are seeing different values for OriginY.

IPAD (in simulator)

display.screenOriginY: -0

display.safeScreenOriginY: 9.375

IPHONE 6 (in simulator)

display.screenOriginY:-44.5

display.safeScreenOriginY:-27.433332443237

This occurs in both the simulator and IOS device builds.  

Is this correct?  possibly moving the safe space to not include the IOS status bar at the top of the screen?  Our app has the status bar disabled. 

It seems like the OriginY should be the same as the safeOriginY with no status bar and not on the iphone X

Of course, they are going to be different.  Depending on your config.lua’s aspect ratio and because an iPad and iPhone 6 are radically different aspect ratios (iPad 4:3 or 1.3333333333:1 vs. an iPhone 5, 6, 7, 8’s 16:9 or 1.7777778:1) your defined content area, if you’re centering it is going to have extra space.

Now the value of 9.375 for the status bar vs. 17.433 seems a bit of an oddity.

I can ask engineering to consider checking the status of the status bar in the calculations, but I can predict their answer. You know if you’re using a status bar or not. Use the safe area if you are, the normal values if you are not.  

It only becomes an issue on iPhone X or Android with sticky immersive button bars.

Rob

Hey Rob… thanks for the response.

I definitely understand that the iphone and ipad will have different values.  That makes total sense.  I was just listing both as examples.

Lets take the regular iphone 6 as an example…  From your documentation it sounded like the display.safeScreenOriginY would be the same as display.screenOriginY.   There is no notch like an iphone X and the status bar is hidden. 

It seems like the top of the screen should be included in the safe area but it is not.  Safe area starts below the top of the screen (screenOriginY)  This throws off our alignment. 

IPHONE 6 (in simulator)

display.screenOriginY:-44.5

display.safeScreenOriginY:-27.433332443237

Using the safeArea setting works great for iphone X but but leaves a gap at top on other iphones.  I have included a screen shot of the app in simulator.  The iphone 6 image on the left has a white gap at the top.   We are using the display.safeScreenOriginY as the top of the orange bar on both screen shots. 

I did not want to have to detect an iphone X and special case it.   Right now the only way to get it to work would be to use the safeScreenOriginY on iphone X and the screenOrigniY on other devices.

I could be thinking about this wrong… so please let me.  Appreciate your help!!!

Hello. We decided to follow Apple’s guides for safe area insets. Basically, if you render content inside safe area it means that it will not be obscured by bezels or status bars, or any system UIs on android. This is how API worked for a while now. Most of the difference in Corona 3173 that Simulators now follow same rules as devices did before.

I understand that you have non-game app in which it is not appropriate to hide status bar. but if you do, you’ll see that on all devices but iPhone X safe areas would be same as content areas.

Basically, you should fill whole Content Area, but position important bits inside Safe Area. You can stretch your title bar background from “contentOriginY” to “safeScreenOriginY+titleBarIconsHeight”, and render your title bar icons centred in safeScreenOriginY+titleBarIconsHeight*0.5.

This way you would always have nice looking title bar icons below iPhone X bezels or ordinary iPhone’s status bars, or just on top of the screen if status bar is off. 

I think code with some pictures would be easiest explanation here. So, I made a snippet. It draws titlebar, and 5 round buttons in the beginning of it. Titlebar has grey background.

[lua]

display.setStatusBar( display.HiddenStatusBar )

– comment out next line to hide status bar

display.setStatusBar( display.DarkTransparentStatusBar )

local titleBarHeight = 30

– it is easier just to create/destroy elements when device is rotated in such simple case

– so we’ll jsut put all elements in group, and re-create it every time we need to resize

local group = display.newGroup()

local function reCreateElements ( )

    – re-create group with titlebar elements

    group:removeSelf( )

    group = display.newGroup()

    – creating grey titlebar background

    – it starts from screen origin, and goes down from safe area beginning to titleBarHeight

    local x0 = display.screenOriginX – left of the screen

    local y0 = display.screenOriginY – top of the screen

    local x1 = display.screenOriginX + display.actualContentWidth – right of the screen

    local y1 = display.safeScreenOriginY + titleBarHeight – space for title bar after safe area

    local titleBarBackground = display.newRect(group, (x0+x1)*0.5, (y0+y1)*0.5, x1-x0, y1-y0)

    titleBarBackground:setFillColor( 0.9 )

    local buttonsY = display.safeScreenOriginY + 0.5*titleBarHeight  – buttons are centred in the middle of status bar

    local buttonsX = display.safeScreenOriginX  – button start from left of status bar

    – create 5 buttons

    for i = 0, 4 do

        local r = 0.5*titleBarHeight  – radius

        local x = buttonsX + (i*2+1)*r  – each button has width 2*radius, plus one radius offset for first button

        local y = buttonsY

        local button = display.newCircle(group, x,y, r)

        button:setFillColor( math.random()*0.5+0.2,math.random()*0.5+0.2,math.random()*0.5+0.2 )

    end 

    – -- this just to demonstrate area one has to use to draw actual title bar content

    – local areaWhereActualTitleBarContentIs = display.newRect(group, display.safeScreenOriginX,display.safeScreenOriginY, display.safeActualContentWidth, titleBarHeight)

    – areaWhereActualTitleBarContentIs.anchorX, areaWhereActualTitleBarContentIs.anchorY = 0, 0

    – areaWhereActualTitleBarContentIs:setFillColor( 0,0,0,0.1 )

end

reCreateElements()

– when device is rotated, just re-create all elements

Runtime:addEventListener( “resize”, reCreateElements )

[/lua]

Here’s some screenshots:

iPhone 6 without status bar

kYUqccL.png

iPhone 6 with status bar

JAoopvR.png

iPhone X portrait:

RLQ2Lqi.png

iPhone X landscape:

eCw7tSS.png

As you can see, using safe area + content area can make your app adaptable to pretty much any screen configuration…

Thanks for the sample. It was helpful!!!  Think we figured out our problem.  We were initializing a few things before setting …display.setStatusBar( display.HiddenStatusBar )…This was causing the our calculations/screen positioning to be incorrect.   We have it working better now!