Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed iPhone 14, 15 and 16 series status bar height issue #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
86 changes: 51 additions & 35 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Dimensions, Platform, StatusBar } from "react-native";
import { Dimensions, Platform, StatusBar } from 'react-native';

const STATUSBAR_DEFAULT_HEIGHT = 20;
const STATUSBAR_X_HEIGHT = 44;
const STATUSBAR_IP12_HEIGHT = 47;
const STATUSBAR_IP12MAX_HEIGHT = 47;
const STATUSBAR_IP14PRO_HEIGHT = 49;
const STATUSBAR_IP16PRO_HEIGHT = 51;
const STATUSBAR_IP16PROMAX_HEIGHT = 53;

const X_WIDTH = 375;
const X_HEIGHT = 812;
Expand All @@ -24,7 +26,13 @@ const IP14PRO_HEIGHT = 852;
const IP14PROMAX_WIDTH = 430;
const IP14PROMAX_HEIGHT = 932;

const { height: W_HEIGHT, width: W_WIDTH } = Dimensions.get("window");
const IP16PRO_WIDTH = 402;
const IP16PRO_HEIGHT = 874;

const IP16PROMAX_WIDTH = 440;
const IP16PROMAX_HEIGHT = 956;

const { height: W_HEIGHT, width: W_WIDTH } = Dimensions.get('window');

let statusBarHeight = STATUSBAR_DEFAULT_HEIGHT;
let isIPhoneX_v = false;
Expand All @@ -34,36 +42,44 @@ let isIPhone12Max_v = false;
let isIPhoneWithMonobrow_v = false;
let isIPhoneWithDynamicIsland_v = false;

if (Platform.OS === "ios" && !Platform.isPad && !Platform.isTVOS) {
if (W_WIDTH === X_WIDTH && W_HEIGHT === X_HEIGHT) {
isIPhoneWithMonobrow_v = true;
isIPhoneX_v = true;
statusBarHeight = STATUSBAR_X_HEIGHT;
} else if (W_WIDTH === XSMAX_WIDTH && W_HEIGHT === XSMAX_HEIGHT) {
isIPhoneWithMonobrow_v = true;
isIPhoneXMax_v = true;
statusBarHeight = STATUSBAR_X_HEIGHT;
} else if (W_WIDTH === IP12_WIDTH && W_HEIGHT === IP12_HEIGHT) {
isIPhoneWithMonobrow_v = true;
isIPhone12_v = true;
statusBarHeight = STATUSBAR_IP12_HEIGHT;
} else if (W_WIDTH === IP12MAX_WIDTH && W_HEIGHT === IP12MAX_HEIGHT) {
isIPhoneWithMonobrow_v = true;
isIPhone12Max_v = true;
statusBarHeight = STATUSBAR_IP12MAX_HEIGHT;
} else if (W_WIDTH === IP14PROMAX_WIDTH && W_HEIGHT === IP14PROMAX_HEIGHT) {
isIPhoneWithDynamicIsland_v = true;
statusBarHeight = STATUSBAR_IP14PRO_HEIGHT;
} else if (W_WIDTH === IP14PRO_WIDTH && W_HEIGHT === IP14PRO_HEIGHT) {
isIPhoneWithDynamicIsland_v = true;
statusBarHeight = STATUSBAR_IP14PRO_HEIGHT;
}
if (Platform.OS === 'ios' && !Platform.isPad && !Platform.isTVOS) {
if (W_WIDTH === X_WIDTH && W_HEIGHT === X_HEIGHT) {
isIPhoneWithMonobrow_v = true;
isIPhoneX_v = true;
statusBarHeight = STATUSBAR_X_HEIGHT;
} else if (W_WIDTH === XSMAX_WIDTH && W_HEIGHT === XSMAX_HEIGHT) {
isIPhoneWithMonobrow_v = true;
isIPhoneXMax_v = true;
statusBarHeight = STATUSBAR_X_HEIGHT;
} else if (W_WIDTH === IP12_WIDTH && W_HEIGHT === IP12_HEIGHT) {
isIPhoneWithMonobrow_v = true;
isIPhone12_v = true;
statusBarHeight = STATUSBAR_IP12_HEIGHT;
} else if (W_WIDTH === IP12MAX_WIDTH && W_HEIGHT === IP12MAX_HEIGHT) {
isIPhoneWithMonobrow_v = true;
isIPhone12Max_v = true;
statusBarHeight = STATUSBAR_IP12MAX_HEIGHT;
} else if (W_WIDTH === IP14PROMAX_WIDTH && W_HEIGHT === IP14PROMAX_HEIGHT) {
isIPhoneWithDynamicIsland_v = true;
statusBarHeight = STATUSBAR_IP14PRO_HEIGHT;
} else if (W_WIDTH === IP14PRO_WIDTH && W_HEIGHT === IP14PRO_HEIGHT) {
isIPhoneWithDynamicIsland_v = true;
statusBarHeight = STATUSBAR_IP14PRO_HEIGHT;
}

else if (W_WIDTH === IP16PRO_WIDTH && W_HEIGHT === IP16PRO_HEIGHT) {
isIPhoneWithDynamicIsland_v = true;
statusBarHeight = STATUSBAR_IP16PRO_HEIGHT;
} else if (W_WIDTH === IP16PROMAX_WIDTH && W_HEIGHT === IP16PROMAX_HEIGHT) {
isIPhoneWithDynamicIsland_v = true;
statusBarHeight = STATUSBAR_IP16PROMAX_HEIGHT;
}
}

export const isIPhoneX = () => isIPhoneX_v;
export const isIPhoneXMax = () => isIPhoneXMax_v;
export const isIPhone12 = () => isIPhone12_v;
export const isIPhone12Max = () => isIPhone12Max_v;
export const isIPhoneX = () => isIPhoneX_v;
export const isIPhoneXMax = () => isIPhoneXMax_v;
export const isIPhone12 = () => isIPhone12_v;
export const isIPhone12Max = () => isIPhone12Max_v;
export const isIPhoneWithMonobrow = () => isIPhoneWithMonobrow_v;
export const isIPhoneWithDynamicIsland = () => isIPhoneWithDynamicIsland_v;

Expand All @@ -72,9 +88,9 @@ const getExpoRoot = () => global.Expo || global.__expo || global.__exponent;
export const isExpo = () => getExpoRoot() !== undefined;

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