cordova-plugin-statusbar
cordova-plugin-statusbar copied to clipboard
feat: get statusbar height (top-inset)
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
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.
The PR is ready for review.
What about your method for getting the height of the status bar,I think it's a necessary method for cordova-plugin-statusbar
How compatible is your method? ios 9? android 4 or 5 above?
@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.
@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!
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 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 :)
Hi @breautek, here's the friendly reminder that you requested! Please take a look at my changes whenever you can :)
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.
This is very useful, when could you release this functionality, please?
@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
@breautek FWIW, we are running this branch in a production application on iOS and Android without issues.
@breautek please notify if you ain't going to merge that.
@breautek This is a useful functionality. Do you have plan to merge it? Thanks.
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 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.
Cant install ionic cordova plugin add...
@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?
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?
@breautek When will this branch be merged?
Really need this feature for my app. When will it be merged? @breautek
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!!!
Really need this feature for my app. When will it be merged? @breautek
Me too :)
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
}
Really need this feature for my app. When will it be merged? @breautek
Same here, can't wait to be merged :)
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.
Why hasn't this pull been merged for so long?
So, any plans to integrate this into master branch?
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...