Skip to content

Commit f27628a

Browse files
authored
fix container top position for iphone12-13 (#47)
* fix margin top for iphone12-13 * import statusbar
1 parent 614575e commit f27628a

File tree

2 files changed

+59
-19
lines changed

2 files changed

+59
-19
lines changed

src/utils/index.js

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,57 @@
1-
import { Dimensions, Platform } from 'react-native';
2-
3-
// Code borrowed from https://github.com/ptelad/react-native-iphone-x-helper
4-
export function isIphoneX() {
5-
const dimen = Dimensions.get('window');
6-
return (
7-
Platform.OS === 'ios' &&
8-
!Platform.isPad &&
9-
!Platform.isTVOS &&
10-
((dimen.height === 812 || dimen.width === 812) || (dimen.height === 896 || dimen.width === 896))
11-
);
12-
}
1+
import { Dimensions, Platform, StatusBar } from 'react-native';
2+
3+
// Code borrowed from https://github.com/ovr/react-native-status-bar-height
4+
const STATUSBAR_DEFAULT_HEIGHT = 20;
5+
const STATUSBAR_X_HEIGHT = 44;
6+
const STATUSBAR_IP12_HEIGHT = 47;
7+
const STATUSBAR_IP12MAX_HEIGHT = 47;
8+
9+
const X_WIDTH = 375;
10+
const X_HEIGHT = 812;
11+
12+
const XSMAX_WIDTH = 414;
13+
const XSMAX_HEIGHT = 896;
14+
15+
const IP12_WIDTH = 390;
16+
const IP12_HEIGHT = 844;
17+
18+
const IP12MAX_WIDTH = 428;
19+
const IP12MAX_HEIGHT = 926;
20+
21+
const { height: W_HEIGHT, width: W_WIDTH } = Dimensions.get("window");
22+
23+
let statusBarHeight = STATUSBAR_DEFAULT_HEIGHT;
24+
let isIPhoneX_v = false;
25+
let isIPhoneXMax_v = false;
26+
let isIPhone12_v = false;
27+
let isIPhone12Max_v = false;
28+
let isIPhoneWithMonobrow_v = false;
29+
30+
if (Platform.OS === "ios" && !Platform.isPad && !Platform.isTVOS) {
31+
if (W_WIDTH === X_WIDTH && W_HEIGHT === X_HEIGHT) {
32+
isIPhoneWithMonobrow_v = true;
33+
isIPhoneX_v = true;
34+
statusBarHeight = STATUSBAR_X_HEIGHT;
35+
} else if (W_WIDTH === XSMAX_WIDTH && W_HEIGHT === XSMAX_HEIGHT) {
36+
isIPhoneWithMonobrow_v = true;
37+
isIPhoneXMax_v = true;
38+
statusBarHeight = STATUSBAR_X_HEIGHT;
39+
} else if (W_WIDTH === IP12_WIDTH && W_HEIGHT === IP12_HEIGHT) {
40+
isIPhoneWithMonobrow_v = true;
41+
isIPhone12_v = true;
42+
statusBarHeight = STATUSBAR_IP12_HEIGHT;
43+
} else if (W_WIDTH === IP12MAX_WIDTH && W_HEIGHT === IP12MAX_HEIGHT) {
44+
isIPhoneWithMonobrow_v = true;
45+
isIPhone12Max_v = true;
46+
statusBarHeight = STATUSBAR_IP12MAX_HEIGHT;
47+
}
48+
}
49+
50+
export function getStatusBarHeight() {
51+
return Platform.select({
52+
ios: statusBarHeight,
53+
android: StatusBar.currentHeight,
54+
default: 0,
55+
});
56+
}
57+

src/views/DefaultPopup.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@ import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import { Animated, View, Text, Image, Dimensions, Platform, StatusBar, StyleSheet, PanResponder, TouchableWithoutFeedback } from 'react-native';
44

5-
import { isIphoneX } from '../utils';
5+
import { getStatusBarHeight } from '../utils';
66

77
const { width: deviceWidth } = Dimensions.get('window');
88

9-
const CONTAINER_MARGIN_TOP = (
10-
Platform.OS === 'ios'
11-
?
12-
isIphoneX() ? 44 : 20
13-
:
14-
StatusBar.currentHeight + 10); // Just to add a bit more padding
9+
const CONTAINER_MARGIN_TOP = getStatusBarHeight() + 10; // Just to add a bit more padding
1510

1611
const slideOffsetYToTranslatePixelMapping = {
1712
inputRange: [0, 1],

0 commit comments

Comments
 (0)