npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@aashu-dubey/capacitor-statusbar-safe-area

v3.0.0

Published

Get Status bar height and Safe area insets on Android & iOS.

Downloads

5,283

Readme

capacitor-statusbar-safe-area

Get Status bar height and Safe area insets on Android & iOS.

npm npm Install Size

Install

npm install @aashu-dubey/capacitor-statusbar-safe-area
npx cap sync

Usage

import { SafeArea } from '@aashu-dubey/capacitor-statusbar-safe-area';

const getStatusBarHeight = async () => {
  const { height } = await SafeArea.getStatusBarHeight();
  return height; // Ex. 29.090909957885742
};

const getSafeAreaInsets = async () => {
  const insets = await SafeArea.getSafeAreaInsets();
  return insets; // Ex. { "bottom":34, "top":47, "right":0, "left":0 }
};

CSS Variables

Package also exposes CSS variables, for that you need to call injectCSSVariables method in your platform.ready() function or whenever app System UI visibility is changed

import { SafeAreaController } from '@aashu-dubey/capacitor-statusbar-safe-area';

const injectSafeAreaVariables = () => {
  SafeAreaController.injectCSSVariables();
};

then you can use them in your CSS files

.myContainer {
  // '--status-bar-height' & '--safe-area-inset-top' would most probably be same
  margin-top: var(--status-bar-height);
}

.myElement {
  padding-top: var(--safe-area-inset-top);
  padding-left: var(--safe-area-inset-left);
  padding-right: var(--safe-area-inset-right);
  padding-bottom: var(--safe-area-inset-bottom);
}

HTML Tag

Other than the above options, you can also use safe-area web component exported by the plugin.

Angular

For Angular users, you will get an error warning that this web component is unknown to the Angular compiler. This is resolved by modifying the module that declares your component to allow for custom web components.

// your-component.module.ts
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';

@NgModule({
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})

You also have to register the custom element before using the tag

// app.component.ts or your-component.ts

import { registerSafeAreaElement } '@aashu-dubey/capacitor-statusbar-safe-area';

registerSafeAreaElement();

then just wrap the part you want to apply safe area padding on with safe-area tag as below

<safe-area>
  <!-- Other content -->
</safe-area>

Others

You will have to import the plugin in your component in order to make the web component work.

import { registerSafeAreaElement } '@aashu-dubey/capacitor-statusbar-safe-area';

registerSafeAreaElement();

const MyComponent = () => {
  return (
    <safe-area>
      // Other content
    </safe-area>
  );
}
<template>
  <safe-area>
    <!-- Other content -->
  </safe-area>
</template>

<script setup lang="ts">
import { registerSafeAreaElement } '@aashu-dubey/capacitor-statusbar-safe-area';

registerSafeAreaElement();
</script>

Attributes

There are two attributes, that can be used with the safe-area web component to control it's behaviour, mode & edges.

<safe-area mode="margin" edges="top,left,right"></safe-area>

more details here.

With SSR

The plugin and it's functionalities are client specific and might throw error when used on the server side like #10 and #11, so always make sure to access the plugin on the client side.

Here are some example for a possible solution to use the plugin in:

Capacitor version support

| capacitor | plugin version | | --------- | -------------------- | | v6.x | 3.0.0 | | v5.x | 2.1.0 | | v4.x | >= 1.1.0 && <= 2.0.0 | | v3.x | <= 1.0.1 |

API

getStatusBarHeight()

getStatusBarHeight() => Promise<{ height: number; }>

Get the Status bar height on Android and iOS, and on Web it returns 0.

Returns: Promise<{ height: number; }>


getSafeAreaInsets()

getSafeAreaInsets() => Promise<SafeAreaInset>

Get the Safe area insets for Android and iOS, and on Web it returns 0 for all.

Returns: Promise<SafeAreaInset>


Interfaces

SafeAreaInset

| Prop | Type | Description | | ------------ | ------------------- | -------------------------------- | | top | number | Safe Area inset value at top. | | bottom | number | Safe Area inset value at bottom. | | left | number | Safe Area inset value at left. | | right | number | Safe Area inset value at right. |

SafeAreaHTMLProps

| Prop | Type | Description | | ----------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | mode | 'padding' | 'margin' | Whether to apply safe area insets as padding or margin. default padding. | | edges | string | Specify the edges you want to apply safe area padding on, separated by comma.For example, to apply padding only on top, left and right, edges="top,left,right". default to all edges. |