Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

StatusBar.currentHeight for iOS #23

Open
se-bastiaan opened this issue May 30, 2019 · 2 comments
Open

StatusBar.currentHeight for iOS #23

se-bastiaan opened this issue May 30, 2019 · 2 comments

Comments

@se-bastiaan
Copy link

se-bastiaan commented May 30, 2019

Feature Request

Make the StatusBar height available via a constant on iOS just like on Android.
RCTSharedApplication().statusBarFrame.size.height

Why it is needed

This would make the API more consistent between the platforms. On iOS it used to be the case that the StatusBar was always 20 pt (portrait at least), this has changed since the iPhone X was introduced, since the height on such devices is 44. The problem is now similar to Android, if you want to use the StatusBar height in a calculation on iOS you need to guess it based on the full screen size. This guessing would be solved by exposing the height of the StatusBar using a constant just like the implementation for Android.

I am aware of the existence of the (internal?) getHeight callback API that is exposed by the native iOS module, however since the StatusBar height is mostly static so I think the current documented Android API is better.

Possible implementation

Just like the Android implementation: using the constant exporting feature that native modules have.

Code sample

- (NSDictionary *)constantsToExport
{
  return @{ @"HEIGHT": @(RCTSharedApplication().statusBarFrame.size.height), };
}
@se-bastiaan
Copy link
Author

I also saw #22 and I can imagine that constant exports are actually not the best implementation for both iOS and Android. However, an async solution would not be easy to work given that this is actually part of the state of your app but still something that you want to have available in a StyleSheet for example. Since the API for Android already exists I thought it wouldn't harm to suggest this implementation anyways. Solving dynamic values can then be seen as a separate issue.

@dmtrKovalenko
Copy link
Collaborator

Any help is totally appreciated :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants