cordova-plugin-statusbar icon indicating copy to clipboard operation
cordova-plugin-statusbar copied to clipboard

feat: get statusbar height (top-inset)

Open XxAdi101xX opened this issue 5 years ago • 28 comments

Platforms affected

The main platform that this is desired for is Android. But this enhancement works on iOS as well.

Motivation and Context

This adds a function that allows us to get the height of the status bar. This is inspired from this issue https://github.com/ionic-team/ionic/issues/17927 where the safe-inset paramters are not respected for Android devices so there is no way to get the statusbar height to enable appropriate styles to support app overlays.

This resolves #112 .

Testing

With testing, the current android implementation AND iOS implementation along with the javascript bridge is working as intended! On an iPhone X, we get a value of 44px as intended. And on an android phone with and without a notch, we get the respective heights of statusbar. Required tests have been added.

Checklist

  • [x] I've run the tests to see all new and existing tests pass
  • [x] If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • [x] I added automated test coverage as appropriate for this change
  • [x] Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • [x] I've updated the documentation if necessary

XxAdi101xX avatar Mar 29 '19 16:03 XxAdi101xX

The code has been tested on both iOS and Android devices. Will add some tests next and update the docs as well. The tests seem to be CI tests seem to be failing because xCode isn't installed on the test pipelines and hence those need to be updated by the owner of the repo.

XxAdi101xX avatar Apr 05 '19 02:04 XxAdi101xX

The PR is ready for review.

XxAdi101xX avatar Apr 05 '19 02:04 XxAdi101xX

What about your method for getting the height of the status bar,I think it's a necessary method for cordova-plugin-statusbar

chavesgu avatar Apr 16 '19 09:04 chavesgu

How compatible is your method? ios 9? android 4 or 5 above?

chavesgu avatar Apr 16 '19 10:04 chavesgu

@chavesgu I have implemented the method for getting the height of the statusbar for both iOS and android. iOS compatibility does work with ios 9 since the method to get the statusbar on iOS was already used to implement some of the other methods in this repository already so it's just exposing a method that was always used. For Android, Android 4 above is supported. See https://stackoverflow.com/questions/29398929/how-get-height-of-the-status-bar-and-soft-key-buttons-bar. Overall, the solution is very compatible with older versions.

XxAdi101xX avatar Apr 23 '19 15:04 XxAdi101xX

@janpio hi, it's been a while since I've submitted this pr. Do you have any information regarding whether this is in a queue to be reviewed, or what the general status is in general. Thanks!

XxAdi101xX avatar Oct 24 '19 18:10 XxAdi101xX

Things have changed since your PR and there is an outstanding merge conflict. Once that is resolved, I can look at the android side of things. Just tag me and I'll try to look at it within a week... and if I don't then feel free to ping me again.

breautek avatar Oct 24 '19 20:10 breautek

@breautek thanks for reaching out, I just resolved the merge conflict with the README.md file and there are no more conflicts. Please take a look whenever you can, thanks :)

XxAdi101xX avatar Oct 24 '19 21:10 XxAdi101xX

Hi @breautek, here's the friendly reminder that you requested! Please take a look at my changes whenever you can :)

XxAdi101xX avatar Nov 25 '19 20:11 XxAdi101xX

I think android looks fine.

Tested on android emulator and seems to work perfectly with both screen cutouts and without. Also works with webview overlay which I think is useful.

I'm not very knowledgeable on iOS development, but I think the setKeepCallbackAsBool usage might be out of place.

breautek avatar Nov 26 '19 05:11 breautek

This is very useful, when could you release this functionality, please?

pcsantana avatar Feb 04 '20 12:02 pcsantana

@breautek I think we can learn if it doesn't work really fine on iOS faster, if the MR is accepted, because people are going to use this

EKashpersky avatar Mar 05 '20 10:03 EKashpersky

@breautek FWIW, we are running this branch in a production application on iOS and Android without issues.

marpstar avatar Mar 05 '20 15:03 marpstar

@breautek please notify if you ain't going to merge that.

EKashpersky avatar Mar 06 '20 19:03 EKashpersky

@breautek This is a useful functionality. Do you have plan to merge it? Thanks.

jenerse avatar Apr 13 '20 07:04 jenerse

Before this can be merged we will need:

  • https://github.com/apache/cordova-plugin-statusbar/pull/134#discussion_r350545105 to be addressed
  • A second PMC member, preferably one who is knowledgeable about iOS to vote in favour.

breautek avatar Apr 13 '20 13:04 breautek

@breautek FWIW, we are running this branch in a production application on iOS and Android without issues.

Tested these changes on various devices (iOS and Android), always computes the correct statusbar height. Will use it in our production apps. Hopefully we will see the changes in one of the upcoming releases.

0x253 avatar Apr 23 '20 11:04 0x253

Cant install ionic cordova plugin add...

vadimwe avatar Apr 27 '20 14:04 vadimwe

@stevengill, @erisu, is there something we can help with to get some of these PRs merged? Would you like us to provide some code cleanup? Provide rebased branches (with proper attribution to the original author) or with more granular changes and some extra tests?

SchnWalter avatar Jun 22 '20 18:06 SchnWalter

This would be a really helpful feature to programmatically adjust layouts after orientation changes. And it feels as though getting the height of the status bar should be a feature of this plugin. Its a bit disappointing that this was contributed well over a year ago, but never merged. Any chance this could be closed out?

jglesner avatar Jul 24 '20 01:07 jglesner

@breautek When will this branch be merged?

jenerse avatar Dec 08 '20 01:12 jenerse

Really need this feature for my app. When will it be merged? @breautek

shivankacker avatar Jan 16 '21 15:01 shivankacker

Hello, I have seen that you have implemented this in production. I am using Ionic, and I cannot find a way to use this function (as Ionic's StatusBar library does not have this funcion implemented). Let me describe the issue.

If I try to use StatusBar via

declare let window any;

it seems that the height function is not defined, as printing window.StatusBar gives me:

StatusBar:  
backgroundColorByHexString: ƒ (hexString)
backgroundColorByName: ƒ (colorname)
hide: ƒ ()
isVisible: true
overlaysWebView: ƒ (doOverlay)
show: ƒ ()
styleBlackOpaque: ƒ ()
styleBlackTranslucent: ƒ ()
styleDefault: ƒ ()
styleLightContent: ƒ ()
__proto__: Object

Just to clarify, I am using cordova via ionic cordova run android and using the device inspector to view the console output.

Sorry if this is a somewhat naive question, but I have been reading about this for days and I cannot seem to find any way to make this function callable. Any help would be appreciated!!!

mianfg avatar Apr 14 '21 09:04 mianfg

Really need this feature for my app. When will it be merged? @breautek

Me too :)

nijakobius avatar Apr 22 '21 16:04 nijakobius

Tested on android emulator and seems to work perfectly, except in Android's Multi-Window mode, for instance, when in portrait orientation, the status bar might be visible if I'm the top app, but won't be visible when I'm the bottom app.

Maybe it can be implemented like this in Javascript:

StatusBar.height(onSuccess, onError);

const onSuccess = (height, statusBarHidden) => {
    // do something with the statusbar height here
}

const onError = (error) => {
    // handle error state; should usually not ever activate
}

ollm avatar May 21 '21 12:05 ollm

Really need this feature for my app. When will it be merged? @breautek

Same here, can't wait to be merged :)

piwpio avatar May 26 '21 20:05 piwpio

I'm surprised that this has not been approved yet after all this time. I had started to use this custom branch for my projects but it would be ideal if it's part of the main branch given the demand.

XxAdi101xX avatar May 26 '21 22:05 XxAdi101xX

Why hasn't this pull been merged for so long?

coloz avatar Oct 03 '21 16:10 coloz

So, any plans to integrate this into master branch?

SunboX avatar Apr 13 '23 13:04 SunboX

Is this PR going to be merged? I see there are 3 pending reviews, I would like to use this with my ionic cordova app. So it would be nice if this could be merged into master so that ionic native can update to the latest package.

Please let us know what will happen to this...

Simbaclaws avatar Nov 08 '23 08:11 Simbaclaws