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

add getHomeIndicatorHeight for iOS devices #9

Open
wants to merge 2 commits 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
38 changes: 28 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
// @flow
import { Dimensions, Platform, StatusBar } from 'react-native';
import { Dimensions, PixelRatio, Platform, StatusBar } from "react-native";

const X_WIDTH = 375;
const X_HEIGHT = 812;

const XSMAX_WIDTH = 414;
const XSMAX_HEIGHT = 896;

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

let isIPhoneX = false;
let isIPhoneXR = false;

if (Platform.OS === 'ios' && !Platform.isPad && !Platform.isTVOS) {
isIPhoneX = W_WIDTH === X_WIDTH && W_HEIGHT === X_HEIGHT || W_WIDTH === XSMAX_WIDTH && W_HEIGHT === XSMAX_HEIGHT;
if (Platform.OS === "ios" && !Platform.isPad && !Platform.isTVOS) {
isIPhoneX =
(W_WIDTH === X_WIDTH && W_HEIGHT === X_HEIGHT) ||
(W_WIDTH === XSMAX_WIDTH && W_HEIGHT === XSMAX_HEIGHT);
}

export function getStatusBarHeight(skipAndroid: boolean = false): number {
return Platform.select({
ios: isIPhoneX ? 44 : 20,
android: skipAndroid ? 0 : StatusBar.currentHeight,
default: 0
})
isIPhoneXR = PixelRatio.get() === 3;
Copy link
Owner

@ovr ovr Mar 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! I suggest to replace this code with

const XR_WIDTH = XXX;
const XR_HEIGHT = XXX;

height == XR_WIDTH || width == XR_HEIGHT

What do you think?

Thanks


let iosBottomBarHeight = 0;

if (isIPhoneX) iosBottomBarHeight = 102* 0,75 ;
else if (isIPhoneXR) iosBottomBarHeight = 68* 0,75;

export function getStatusBarHeight(skipAndroid = false) {
return Platform.select({
ios: isIPhoneX ? 44 : 20,
android: skipAndroid ? 0 : StatusBar.currentHeight,
default: 0
});
}

export function getHomeIndicatorHeight() {
return Platform.select({
ios: iosBottomBarHeight,
android: 0,
default: 0
});
}