From issues-return-98481-apmail-cordova-issues-archive=cordova.apache.org@cordova.apache.org Thu Apr 23 02:45:46 2020 Return-Path: X-Original-To: apmail-cordova-issues-archive@minotaur.apache.org Delivered-To: apmail-cordova-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with SMTP id 62CC31991C for ; Thu, 23 Apr 2020 02:45:46 +0000 (UTC) Received: (qmail 4751 invoked by uid 500); 23 Apr 2020 02:45:46 -0000 Delivered-To: apmail-cordova-issues-archive@cordova.apache.org Received: (qmail 4718 invoked by uid 500); 23 Apr 2020 02:45:45 -0000 Mailing-List: contact issues-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list issues@cordova.apache.org Received: (qmail 4665 invoked by uid 99); 23 Apr 2020 02:45:45 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Apr 2020 02:45:45 +0000 From: =?utf-8?q?GitBox?= To: issues@cordova.apache.org Subject: =?utf-8?q?=5BGitHub=5D_=5Bcordova-plugin-statusbar=5D_SchnWalter_commented_o?= =?utf-8?q?n_a_change_in_pull_request_=23134=3A_feat=3A_get_statusbar_height?= =?utf-8?q?_=28top-inset=29?= Message-ID: <158760994557.3807.9693072162722876167.asfpy@gitbox.apache.org> Date: Thu, 23 Apr 2020 02:45:45 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit References: In-Reply-To: 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: ``` ``` 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