cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [cordova-plugin-statusbar] SchnWalter commented on a change in pull request #134: feat: get statusbar height (top-inset)
Date Thu, 23 Apr 2020 02:45:45 GMT

SchnWalter commented on a change in pull request #134:
URL: https://github.com/apache/cordova-plugin-statusbar/pull/134#discussion_r413468163



##########
File path: src/android/StatusBar.java
##########
@@ -206,6 +212,16 @@ public void run() {
         return false;
     }
 
+    private float getStatusBarHeight() {
+        float statusBarHeight = 0;
+        int resourceId = cordova.getActivity().getResources().getIdentifier("status_bar_height",
"dimen", "android");
+        if (resourceId > 0) {
+            float scaleRatio = cordova.getActivity().getResources().getDisplayMetrics().density;
+            statusBarHeight = cordova.getActivity().getResources().getDimension(resourceId)
/ scaleRatio;
+        }
+        return statusBarHeight;

Review comment:
       Tested on a v27 emulator and on a v29 device, it works; Thanks!
   
   I think that this feature will be used a lot to expose the height in a CSS variable, and
I think that it might make sense to expose it directly in the plugin. I'm currently setting
the CSS variable like this:
   ```js
   const onSuccess = (height: number): void => {
     const roundedHeight = Math.ceil(height);
     if (isNaN(roundedHeight)) {
       document.documentElement.style.setProperty('--cordova-status-bar-height', '0px');
       console.warn('Failed to determine the StatusBar height.')
     } else {
       document.documentElement.style.setProperty('--cordova-status-bar-height', `${height}px`);
     }
   };
   ```
   And in CSS:
   ```css
   .my-toolbar-container {
       padding-top: calc(8px + var(--cordova-status-bar-height));
   }
   ```
   But in order for this to work properly in all cases, the CSS variable value needs to be
updated on each screen orientationchange. Because, in some cases, the StatusBar height depends
on the height of the screen notch and if you rotate the screen, then the status bar height
might be different depending if you have a notch or not.
   
   It would be nice if the user could just set a:
   ```
   <preference name="StatusBarHeightCSSVariable" value="true" />
   ```
   In order to use a CSS variable directly, without having to write any JS in order to fetch
the height and to subscribe to the screen orientation changes.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


Mime
View raw message