You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by GitBox <gi...@apache.org> on 2021/04/22 16:31:49 UTC

[GitHub] [cordova-plugin-statusbar] nielsjakob commented on issue #112: how to get statusbar height

nielsjakob commented on issue #112:
URL: https://github.com/apache/cordova-plugin-statusbar/issues/112#issuecomment-824996178


   > This is what I did.
   > 
   > * First, set the overlay to false
   > * then get the current value of document.documentElement.clientHeight
   > * then set the overlay to true
   > * then get the current value of document.documentElement.clientHeight
   > * the difference of currentHeight  and initialHeight should be the safe area
   > 
   > ```
   > const setSafeArea= async () => {
   >   await Plugins.StatusBar.setOverlaysWebView({
   >     overlay: false,
   >   })
   >   await delay(0)
   >   const initialHeight = document.documentElement.clientHeight
   >   await Plugins.StatusBar.setOverlaysWebView({
   >     overlay: true,
   >   })
   >   await delay(0)
   >   const currentHeight = document.documentElement.clientHeight
   >   const safeArea = currentHeight - initialHeight
   >   document.documentElement.style.setProperty('--safe-area-top', `${safeArea}px`)
   > }
   > ```
   
   @ronn9419 That doesn't work for me unfortunately. The following does sort of, but only if I manually set a rather long delay (1000ms)...
   
   (Why are you using `Plugins.StatusBar.setOverlaysWebView({overlay: false})` instead of `StatusBar.overlaysWebView(false)`?)
   
   ```
   (async () => {
         await StatusBar.overlaysWebView(false);
         var initialHeight = document.documentElement.clientHeight;
         await StatusBar.overlaysWebView(true);
         await delay(1000);
         var currentHeight = document.documentElement.clientHeight;
         console.log('safeArea', currentHeight - initialHeight);
       })();
       function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
   ```


-- 
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