display.topStatusBarContentHeight not working

display.topStatusBarContentHeight seems to be working great in the corona simulator, but is set to 0 in xcode simulator and on iOS devices. Anybody know what’s going on? I’m using the “ultimate config.lua file” by Rob Miracle for content scaling

Well the config.lua shouldn’t impact this.   What device are you using?

The deprecated display.statusBarHeight API call might be a clue:

http://docs.coronalabs.com/api/library/display/statusBarHeight.html

display.topStatusBarContentHeight seems to be working great in the corona simulator, but is set to 0  in xcode simulator and on iOS devices. Anybody know what’s going on? I’m using the “ultimate config.lua file” by Rob Miracle for content scaling

also, using Corona 2013.1076 (latest public release).

statusbar.jpg

Well the config.lua shouldn’t impact this.   What device are you using?

The deprecated display.statusBarHeight API call might be a clue:

http://docs.coronalabs.com/api/library/display/statusBarHeight.html

display.topStatusBarContentHeight seems to be working great in the corona simulator, but is set to 0  in xcode simulator and on iOS devices. Anybody know what’s going on? I’m using the “ultimate config.lua file” by Rob Miracle for content scaling

also, using Corona 2013.1076 (latest public release).

statusbar.jpg

I confirm that display.topStatusBarContentHeight does not work. However, display.statusBarHeight does work.

I am using Corona Version 2013.1133 (2013.5.29), today’s download.

I think I have discovered how this works: if the status bar is hidden, then the height is zero. If it is showing then display.topStatusBarContentHeight does return the correct height.

However, display.statusBarHeight returns the correct height even if the bar is not showing.

One thing to watch out for is that “display.statusBarHeight” returns the height in pixels and not content coordinates, which are the scaled coordinates relative to what you’ve set up in your config.lua file.  So, if you use the “display.statusBarHeight” property instead, you’ll need to convert the height to content coordinates by multiplying it against the “display.contentScaleY” property.  Or… you can just make it easier on yourself and use our new “display.topStatusBarContentHeight” property instead.

Is there some way we can get display.topStatusBarContentHeight to give us the status bar height even if the status bar isn’t showing at the moment we ask for the height?

The following seems to work iOS Simulator.

function getStatusBarHeight() local t = display.topStatusBarContentHeight if (t == 0) then display.setStatusBar( display.DarkStatusBar ) t = display.topStatusBarContentHeight display.setStatusBar( display.HiddenStatusBar ) end return t end

mimetic,

No.  The “display.topStatusBarContentHeight” is supposed to return the height of the status bar in its “current” state.  So, if the status bar is hidden, then it is supposed to return zero.  This is by design.  Since the status bar is overlaid on top of your app, the idea is to check this property for the status bar’s presence, and if it is there, then relayout your app just under the status bar.

When we add bottom status-bar/navigation-bar support on Android, fetching this height value dynamically (instead of caching it on startup) becomes more important because the height will change when:

  • Switching between portrait and landscape on an Android tablet.

  • Showing/hiding the status bar, which on some tablets merely reduces the bottom bar’s height instead of hiding it.

So, the function I wrote (above) is the right way to handle the status bar height?

I’m pretty sure your solution will *not* work on Android.  The reason is that Android won’t display the status bar immediately because the operation is posted on another thread.  That means you’ll get a value of zero in this case.

Yes, your solution will work for the top status bar on iOS.  I’m not sure if it’ll work on Android since displaying its top status bar is done via another thread, meaning the status bar is not shown yet by the time you are reading its height.

So, the only solution proper is to get the status bar height upon opening the app and store it in a global?

I don’t recommend that you store it at all.  I recommend that you fetch it dynamically via our display.topStatusBarContentHeight instead in case the value changes on you.

Wait…you just wrote I can’t know the height of the status bar on Android unless I magically know when the ‘show’ operation finishes. What I want to do is

(a) show the status bar,

and

(b) layout the screen based on the height of the status bar.

You’re writing that unless the status bar is showing, I won’t know its height…so I can’t layout the screen properly. Help?

>> you just wrote I can’t know the height of the status bar on Android unless I magically know when the ‘show’ operation finishes

I’m actually not 100% positive about this.  I recommend that you try it for yourself.  I’ve yet to hear about any status bar issues on Android, so it may work fine.

I confirm that display.topStatusBarContentHeight does not work. However, display.statusBarHeight does work.

I am using Corona Version 2013.1133 (2013.5.29), today’s download.

I think I have discovered how this works: if the status bar is hidden, then the height is zero. If it is showing then display.topStatusBarContentHeight does return the correct height.

However, display.statusBarHeight returns the correct height even if the bar is not showing.

One thing to watch out for is that “display.statusBarHeight” returns the height in pixels and not content coordinates, which are the scaled coordinates relative to what you’ve set up in your config.lua file.  So, if you use the “display.statusBarHeight” property instead, you’ll need to convert the height to content coordinates by multiplying it against the “display.contentScaleY” property.  Or… you can just make it easier on yourself and use our new “display.topStatusBarContentHeight” property instead.

Is there some way we can get display.topStatusBarContentHeight to give us the status bar height even if the status bar isn’t showing at the moment we ask for the height?

The following seems to work iOS Simulator.

function getStatusBarHeight() local t = display.topStatusBarContentHeight if (t == 0) then display.setStatusBar( display.DarkStatusBar ) t = display.topStatusBarContentHeight display.setStatusBar( display.HiddenStatusBar ) end return t end

mimetic,

No.  The “display.topStatusBarContentHeight” is supposed to return the height of the status bar in its “current” state.  So, if the status bar is hidden, then it is supposed to return zero.  This is by design.  Since the status bar is overlaid on top of your app, the idea is to check this property for the status bar’s presence, and if it is there, then relayout your app just under the status bar.

When we add bottom status-bar/navigation-bar support on Android, fetching this height value dynamically (instead of caching it on startup) becomes more important because the height will change when:

  • Switching between portrait and landscape on an Android tablet.

  • Showing/hiding the status bar, which on some tablets merely reduces the bottom bar’s height instead of hiding it.

So, the function I wrote (above) is the right way to handle the status bar height?