diff --git a/README.md b/README.md index 91e0613..48826d3 100644 --- a/README.md +++ b/README.md @@ -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)); ``` diff --git a/index.js b/index.js index 7452f06..c22c396 100644 --- a/index.js +++ b/index.js @@ -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; @@ -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, }); }