@logicwind/react-native-status-bar-height
Version:
A React Native library for retrieving the status bar height on both Android and iOS.
80 lines (52 loc) • 2.41 kB
Markdown
A simple and lightweight React Native package to get the **status bar height** and **bottom safe area inset** on both Android and iOS.
Using npm:
```sh md title="Terminal"
npm install @logicwind/react-native-status-bar-height
```
or using yarn:
```sh md title="Terminal"
yarn add @logicwind/react-native-status-bar-height
```
After installation, make sure to install CocoaPods:
```sh md title="Terminal"
cd ios && pod install
```
No additional setup is required.
Import and use the utility functions to fetch values:
```tsx md title="App.tsx"
import {
fetchStatusBarHeight,
fetchBottonInset,
} from '@logicwind/react-native-status-bar-height';
const statusBarHeight = fetchStatusBarHeight();
const bottomInset = fetchBottonInset();
```
```tsx md title="App.tsx"
<View style={{ flex: 1 }}>
<Text style={{ marginTop: fetchStatusBarHeight() }}>
Status Bar Height
</Text>
<View style={{ flex: 1 }} />
<Text style={{ marginBottom: fetchBottonInset() }}>
Bottom Safe Area
</Text>
</View>
```
`fetchStatusBarHeight(): number` - Returns the status bar height in pixels.
`fetchBottomInset(): number` - Returns the bottom safe area inset in pixels, helpful for avoiding overlap with gesture/navigation bars.
- On iOS, it retrieves values using native APIs or falls back to common values.
- On Android, it uses StatusBar.currentHeight for the status bar height, and WindowInsets for the bottom inset when available.
- A fallback mechanism is in place to provide reasonable defaults.
We are a 130+ people company developing and designing multiplatform applications using the Lean & Agile methodology. To get more information on the solutions that would suit your needs, feel free to get in touch by [email](mailto:sales@logicwind.com) or through or [contact form](https://www.logicwind.com/contact-us?utm_source=github&utm_medium=github.com-logicwind&utm_campaign=react-native-status-bar-height)!
We will always answer you with pleasure 😁
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details