Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@

> Small library that helps you to get status bar height

P.S :iphone:X supported :heart:
P.S: Monobrow iPhone devices supported :heart: 📱

## Install

```bash
$ npm install --save react-native-status-bar-height
$ npm install --save-exact react-native-status-bar-height
# OR
$ yarn add react-native-status-bar-height
```

## Usage getStatusBarHeight(skipAndroid: boolean = false)
## Usage getStatusBarHeight(skip: boolean = false)

```js
import { getStatusBarHeight } from 'react-native-status-bar-height';

// 44 - on iPhoneX
// 20 - on iOS device
// X - on iOS Monobrow devices (runtime value)
// 30 - if skipped SafeArea on iOS Monobrow device
// 20 - default iOS Value (Non-Monobrow devices)
// X - on Android platfrom (runtime value)
// 0 - on all other platforms (default)
console.log(getStatusBarHeight());

// will be 0 on Android, because You pass true to skipAndroid
// will be 0 on Android, because You pass true to skip
// will skip SafeAreaView on iOS, because You pass true to skip
console.log(getStatusBarHeight(true));
```

Expand Down
19 changes: 16 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Dimensions, Platform, StatusBar } from "react-native";

const STATUSBAR_DEFAULT_HEIGHT = 20;
const STATUSBAR_DEFAULT_HEIGHT_WITH_MONOBROW = 30;
const STATUSBAR_X_HEIGHT = 44;
const STATUSBAR_IP12_HEIGHT = 47;
const STATUSBAR_IP12MAX_HEIGHT = 47;
Expand Down Expand Up @@ -54,12 +55,24 @@ export const isIPhoneWithMonobrow = () => isIPhoneWithMonobrow_v;

const getExpoRoot = () => global.Expo || global.__expo || global.__exponent;

function checkIfSkippedSafeArea(skipSafeArea) {
if (skipSafeArea) {
if (isIPhoneWithMonobrow()) {
return STATUSBAR_DEFAULT_HEIGHT_WITH_MONOBROW;
} else {
return STATUSBAR_DEFAULT_HEIGHT;
}
} else {
return statusBarHeight
}
}

export const isExpo = () => getExpoRoot() !== undefined;

export function getStatusBarHeight(skipAndroid) {
export function getStatusBarHeight(skip) {
return Platform.select({
ios: statusBarHeight,
android: skipAndroid ? 0 : StatusBar.currentHeight,
ios: checkIfSkippedSafeArea(skip),
android: skip ? 0 : StatusBar.currentHeight,
default: 0,
});
}