Skip to content

Commit 32461fe

Browse files
authored
Merge pull request #683 from GetStream/fix-android-translucent-status-bar-keyboard-height
2 parents 4f6feb0 + cac24b4 commit 32461fe

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/components/KeyboardCompatibleView/KeyboardCompatibleView.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
LayoutRectangle,
1313
Platform,
1414
ScreenRect,
15+
StatusBar,
1516
StyleSheet,
1617
View,
1718
} from 'react-native';
@@ -59,11 +60,24 @@ export class KeyboardCompatibleView extends React.Component<
5960
}
6061

6162
const keyboardY =
62-
keyboardFrame.screenY - (this.props.keyboardVerticalOffset as number);
63+
keyboardFrame.screenY - (this.props.keyboardVerticalOffset ?? 0);
64+
const relativeHeight = frame.y + frame.height - keyboardY;
65+
66+
/**
67+
* When the StatusBar is translucent there is an issue
68+
* where the relative keyboard height is returned as the StatusBar
69+
* height instead of 0 when closed.
70+
*/
71+
if (
72+
Platform.OS === 'android' &&
73+
relativeHeight === StatusBar.currentHeight
74+
) {
75+
return 0;
76+
}
6377

6478
// Calculate the displacement needed for the view such that it
6579
// no longer overlaps with the keyboard
66-
return Math.max(frame.y + frame.height - keyboardY, 0);
80+
return Math.max(relativeHeight, 0);
6781
}
6882

6983
_onKeyboardChange: KeyboardEventListener = (event) => {

0 commit comments

Comments
 (0)