Retrieves the safe area insets.
This is EXPERIMENTAL, and I can not guarantee that it works on all android and ios device and configurations.
npm install get-safe-area-capacitor
npx cap sync
GetSafeArea() => Promise<{ top: number; bottom: number; left: number; right: number; }>
import { GetSafeArea } from 'get-safe-area-capacitor'
import { StatusBar } from '@capacitor/status-bar';
if(Capacitor.getPlatform() == "android")
await StatusBar.setOverlaysWebView({ overlay: true });
GetSafeArea().then((e) => {
document.body.style.marginTop = `${e.top}px`;
})
- Remember to add
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
to your head. - Remember to add the style
<item name="android:windowLayoutInDisplayCutoutMode"> shortEdges </item>
to your activity. More Info - Remember to set the content to go underneath the status bar on android.