Skip to content

Commit

Permalink
Apply safeArea only for iPhone X (and newer) (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillplatonov authored and ardaogulcan committed Oct 17, 2018
1 parent db86bad commit f10223a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/KeyboardAccessoryView.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
LayoutAnimation,
Platform,
StyleSheet,
ViewPropTypes
ViewPropTypes,
Dimensions
} from 'react-native';

const accessoryAnimation = (duration, easing, animationConfig = null) => {
Expand Down Expand Up @@ -40,6 +41,9 @@ const accessoryAnimation = (duration, easing, animationConfig = null) => {
)
}

const { height, width } = Dimensions.get('window')
const isSafeAreaSupported = Platform.OS === 'ios' && (height > 800 || width > 800)

class KeyboardAccessoryView extends Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -150,6 +154,7 @@ class KeyboardAccessoryView extends Component {
} = this.props;

const visibleHeight = accessoryHeight + (avoidKeyboard ? keyboardHeight : 0);
const applySafeArea = isSafeAreaSupported && inSafeAreaView;

return (
<View style={{ height: (isKeyboardVisible || alwaysVisible ? visibleHeight : 0) }}>
Expand All @@ -159,8 +164,8 @@ class KeyboardAccessoryView extends Component {
style,
{
opacity: (isKeyboardVisible || alwaysVisible ? visibleOpacity : hiddenOpacity),
bottom: keyboardHeight - bumperHeight - (inSafeAreaView ? 20 : 0),
height: accessoryHeight + bumperHeight + (inSafeAreaView ? (!isKeyboardVisible ? 20 : -10) : 0),
bottom: keyboardHeight - bumperHeight - (applySafeArea ? 20 : 0),
height: accessoryHeight + bumperHeight + (applySafeArea ? (!isKeyboardVisible ? 20 : -10) : 0),
}
]}>
<View onLayout={this.handleChildrenLayout}>
Expand Down

0 comments on commit f10223a

Please sign in to comment.