Git Product home page Git Product logo

Comments (16)

XxAdi101xX avatar XxAdi101xX commented on July 18, 2024 33

The env(safe-area-inset-top) does not work with android. With more and more notched android phones coming out, it makes sense that the statusbar plugin does actually provide the height of the statusbar. At my company, we require the statusbar height to deal with our app styles when we overlay our application with the status bar but are unable to get statusbar height for android devices since the env variables only works for iOS. There seems to be no other solution other than creating a cordova plugin (or additional method to this library) to get this using the getInset function from the application window natively to get our value. Is there a better way to resolve this? @mhartington

from cordova-plugin-statusbar.

cwoolum avatar cwoolum commented on July 18, 2024 4

I'm running into the same issue. The safe area height returned by env(safe-area-inset-top) is always the same on the respective iOS versions but in reality, the notch causes the height to be different

image

from cordova-plugin-statusbar.

coloz avatar coloz commented on July 18, 2024 3

https://www.npmjs.com/package/cordova-plugin-statusbar-latest
use the version,StatusBar.height is used to get StatusBar height

the version from #134

from cordova-plugin-statusbar.

grumpygary avatar grumpygary commented on July 18, 2024 1

Or you could use another plugin to get the height:

https://www.npmjs.com/package/dfocus-fm-cordova-plugin-statusbar-height

It's a bit obscure, but I checked the source and it's really simple and appears to work well (hint to the maintainers of this plugin).

from cordova-plugin-statusbar.

janpio avatar janpio commented on July 18, 2024

No, this is not one of the supported methods: https://github.com/apache/cordova-plugin-statusbar#methods

Why do you need this functionality?

from cordova-plugin-statusbar.

garyganyang avatar garyganyang commented on July 18, 2024

i need this functionality also, cuz i want my statusbar has a liner background: linear-gradient(to right black white) for example, so i choose set StatusBar.overlaysWebView(true) and add a custom "statusBar" which has a linear gradient backgroudColor, meanwhile, different android devices has different height of statusBar, so i need to get the devices height of statusBar to set on my custom ""statusBar""

from cordova-plugin-statusbar.

mhartington avatar mhartington commented on July 18, 2024

Newer versions of iOS and Android provide env-variables in css for this

env(safe-area-inset-top)

Which would return the space reserved for the status bar. But that's only for newer version of the OS. Older versions would not have this. Thankfully, iOS would have ~20px as the height for the status bar, but android could have many different status bar sizes, so there's not way to know for sure.

from cordova-plugin-statusbar.

wwiechorek avatar wwiechorek commented on July 18, 2024

To get statusbar height on android I use in JS:
var statusbarheight = screen.height - window.innerHeight

And I set this variable on css var.

Is it is correct?

from cordova-plugin-statusbar.

danielehrhardt avatar danielehrhardt commented on July 18, 2024

Same Issue here. Did someone found a Solution?

from cordova-plugin-statusbar.

merihs avatar merihs commented on July 18, 2024

Did anyone find a solution?

from cordova-plugin-statusbar.

ptorrent avatar ptorrent commented on July 18, 2024

How can I test it ?

from cordova-plugin-statusbar.

ronn9419 avatar ronn9419 commented on July 18, 2024

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`)
}

from cordova-plugin-statusbar.

nijakobius avatar nijakobius commented on July 18, 2024

This is what I did.

@ronn9419 That doesn't work for me unfortunately. The following does sort of, but only if I manually set a rather long delay (like 1000ms)...

(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)); }

(Why are you using Plugins.StatusBar.setOverlaysWebView({overlay: false}) instead of StatusBar.overlaysWebView(false)?)

from cordova-plugin-statusbar.

nijakobius avatar nijakobius commented on July 18, 2024

The following seems like a better solution:

var initialHeight = document.documentElement.clientHeight;
window.addEventListener('resize', resizeFunction);
function resizeFunction() {
    console.log('STATUS BAR HEIGHT', document.documentElement.clientHeight - initialHeight);
    window.removeEventListener('resize', resizeFunction);
}
StatusBar.overlaysWebView(true);

It takes about 150ms from deviceready.

from cordova-plugin-statusbar.

ptorrent avatar ptorrent commented on July 18, 2024

@nielsjakob looks like the best solution I found... thanks

from cordova-plugin-statusbar.

aacassandra avatar aacassandra commented on July 18, 2024

if you using capacitori, you can use this package
https://github.com/Aashu-Dubey/capacitor-statusbar-safe-area
im already tested on ionic 7 with vue

from cordova-plugin-statusbar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.