Skip to content
This repository was archived by the owner on Dec 3, 2024. It is now read-only.

Commit 8d1fbff

Browse files
committed
Fix iPhone X support
1 parent 33d3701 commit 8d1fbff

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# react-navigation-addon-search-layout
22

33
Note: this currently depends on the Expo environment being present. I
4-
may fix this in the future, a PR is welcome though. More documentation
5-
coming..
4+
may fix this in the future, a PR is welcome though. It also only
5+
explicitly supports portrait mode, ymmv with landscape.
66

77
[Try it on Snack](https://snack.expo.io/HJXlZ7TuW)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-navigation-addon-search-layout",
3-
"version": "0.8.0",
3+
"version": "0.9.0",
44
"main": "index.js",
55
"license": "MIT",
66
"dependencies": {

src/Header.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import React from 'react';
2-
import { Animated, Platform, StyleSheet, View } from 'react-native';
2+
import { Animated, Dimensions, Platform, StyleSheet, View } from 'react-native';
33
import { withNavigation, HeaderBackButton } from 'react-navigation';
44

5+
const X_WIDTH = 375;
6+
const X_HEIGHT = 812;
7+
const { height: D_HEIGHT, width: D_WIDTH } = Dimensions.get('window');
8+
const isIPhoneX =
9+
Platform.OS === 'ios' && (D_HEIGHT === X_HEIGHT && D_WIDTH === X_WIDTH);
10+
11+
const NOTCH_HEIGHT = isIPhoneX ? 20 : 0;
512
const APPBAR_HEIGHT = Platform.OS === 'ios' ? 50 : 56;
613
const STATUSBAR_HEIGHT = Platform.OS === 'ios' ? 20 : 0;
714
const TITLE_OFFSET = Platform.OS === 'ios' ? 70 : 56;
815

916
@withNavigation
1017
export default class Header extends React.PureComponent {
11-
static HEIGHT = APPBAR_HEIGHT + STATUSBAR_HEIGHT;
18+
static HEIGHT = APPBAR_HEIGHT + STATUSBAR_HEIGHT + NOTCH_HEIGHT;
1219

1320
_navigateBack = () => {
1421
this.props.navigation.goBack(null);
@@ -71,8 +78,8 @@ if (Platform.OS === 'ios') {
7178
const styles = StyleSheet.create({
7279
container: {
7380
backgroundColor: '#fff',
74-
paddingTop: STATUSBAR_HEIGHT,
75-
height: STATUSBAR_HEIGHT + APPBAR_HEIGHT,
81+
paddingTop: STATUSBAR_HEIGHT + NOTCH_HEIGHT,
82+
height: STATUSBAR_HEIGHT + APPBAR_HEIGHT + NOTCH_HEIGHT,
7683
...platformContainerStyles,
7784
},
7885
appBar: {

0 commit comments

Comments
 (0)