Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getStatusBarHeight method for Android #98

Closed

Conversation

aszmyd
Copy link

@aszmyd aszmyd commented Jul 18, 2018

Platforms affected

Android

What does this PR do?

Added StatusBar.getStatusBarHeight method (Android only) that gets current statusbar height in CSS pixels

What testing has been done on this change?

Manual testing on Android device

@oliversalzburg
Copy link

What is the purpose of the method? At what point do you need this information in your app?

If anything, I would have expected to see this in the iOS part.

@aszmyd
Copy link
Author

aszmyd commented Jul 18, 2018

When you use StatusBar.overlaysWebView(true); method to have "transparent" statusbar and you want to pull down contents so they won't conflict with statusbar, you need to know how tall is the transparent statusbar. If there is any other way to achieve that, im keen to read about it. Android devices are different also so the statusbar height can vary. iOS mostly has 20px from top as far as i know. iPhoneX has some css variables to use to get top padding.

Copy link
Contributor

@Menardi Menardi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this PR. Isn't the Android status bar usually 24dp? In practice that would always be 24px in a Cordova app, and it has usually worked well for me. Having a function to calculate it could be useful, though it's possible this implementation wouldn't work in all cases (e.g. split screen). What do you think?

www/statusbar.js Outdated
exec(function (result) {
successCallback(result);
}, errorCallback, "StatusBar", "getStatusBarHeight", []);
StatusBar.isVisible = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it's left over from a copy-paste of show

Rect rectangle = new Rect();
Window window = cordova.getActivity().getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
int statusBarHeight = Math.round(rectangle.top / Resources.getSystem().getDisplayMetrics().density);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the app is on the bottom of a split-screen, will this return the offset from the top of the screen? If so, this value will be incorrect.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I see the issue and im trying to figure out an fix for this.

@aszmyd
Copy link
Author

aszmyd commented Jul 19, 2018

I've pushed changes that fixes split mode issue - If we detect that we're in split mode at the bottom, we simply return height 0 as there is no real statusbar at the top of our app.

@Menardi
Copy link
Contributor

Menardi commented Jul 20, 2018

@aszmyd Looking at the Android code, the statusbar height is always 24dp (see https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/dimens.xml#35). So, in a Cordova app, this would always be 24px, since the webview scales to have 1dp == 1px. Have you observed any other values? I'm inclined to just add a line to the docs saying the status bar height is always 24px. Do you think this would be sufficient?

@aszmyd
Copy link
Author

aszmyd commented Jul 20, 2018

@Menardi i think you're right. I've pushed a change with constant and some readme updates. Please check out.

@Menardi
Copy link
Contributor

Menardi commented Jul 20, 2018

@aszmyd I was was more thinking that since it's always 24px, there's no need for the getStatusBarHeight function at all. Just a note in the docs saying that users can use 24px in their CSS would probably be enough.

@aszmyd
Copy link
Author

aszmyd commented Jul 20, 2018

@Menardi i thought about that too but how would user app detect split mode issue? If user statically set 24px then even in split mode it'll use that.

@Menardi
Copy link
Contributor

Menardi commented Jul 20, 2018

True, but I think that is a different scenario in a way. I'm not sure Cordova apps even officially support split screen mode. If it is supported, I think it would make more sense for the Cordova core to handle the split screen change, rather than this plugin. Then the user could handle this scenario themselves.

@aszmyd
Copy link
Author

aszmyd commented Jul 20, 2018

The main issue is that when statusbar is transparent and overlapping webview, app does not know how much space it needs to leave in order for everything too look sane. I think this approach (with resulting 0 in split mode) allows easily to fix that and i believe it'll fit needs of a lot apps, not just the one im working on. Alternative would be to complicate logic and have separate plugin to detect split mode and behave differently on app-level. @Menardi if you strongly don't want this method to be present, i cannot force you but i really think it can bring more benefits than harm :)

@Menardi
Copy link
Contributor

Menardi commented Jul 21, 2018

Personally I think the split-screen logic should be in the core, because there are more use cases for it apart from the status bar. So, I don't think there is a need for getStatusBarHeight. But, I am open to other opinions. Perhaps someone else could jump in here?

@IndieSW
Copy link

IndieSW commented Jul 21, 2018

In 4.4, the status bar height is 25 dp. And I don't believe it's guaranteed not to change.

@aszmyd
Copy link
Author

aszmyd commented Jul 23, 2018

Ok i understand your concerns. Thanks for your time. I'm closing this PR

@aszmyd aszmyd closed this Jul 23, 2018
@FreekMencke
Copy link

FreekMencke commented Nov 7, 2018

On my One Plus 6 the status bar is 30px in cordova. It's definitly not always 24px. Can this be reopenend?

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

Successfully merging this pull request may close these issues.

6 participants