Comments (16)
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.
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
from cordova-plugin-statusbar.
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.
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.
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.
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.
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.
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.
Same Issue here. Did someone found a Solution?
from cordova-plugin-statusbar.
Did anyone find a solution?
from cordova-plugin-statusbar.
How can I test it ?
from cordova-plugin-statusbar.
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.
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.
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.
@nielsjakob looks like the best solution I found... thanks
from cordova-plugin-statusbar.
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)
- Failed to fetch plugin cordova-plugin-statusbar@cordova-plugin-statusbar via registry. HOT 4
- Add success and error callbacks for the `overlaysWebView` method
- StyleDefault will set light text instead of dark. HOT 3
- Xcode 12 and iOS 9.0 various deprecation
- 2.4.3 BROKEN - Replacement Release Desperately Needed HOT 5
- iOS - HTML video player full screen causes web view overlay issues HOT 2
- Empty space below the status bar on devices without notch and iOS 15.4 HOT 5
- Webview doesn't take full height after hide
- Device elements overlap ionic header HOT 6
- On android 12, statusbar styleDefault method not work as expected
- iPhone 14 Pro floating island status bar height incorrect HOT 5
- Status bar background color overridden on Android 13 HOT 2
- backgroundColorByHexString does not work? HOT 2
- Plugin not working on Android 13 with cordova [email protected] HOT 10
- change statusBar background color and icon color for only one screen(Page) for iOS and android HOT 1
- Android top and bottom content overlapped by status bar after upgrade from 2.4.3 to 3.0.0 HOT 9
- StatusBar not changing Color on Android 13 HOT 7
- StatusBar still there, stopped to work HOT 1
- Playing video on iOS and shifting from landscape to portrait messes up status bar HOT 5
- Bottom nav bar overlaps webview in Android 13 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cordova-plugin-statusbar.