The height of the keyboard as reported by the keyboardDidShow event is wrong when a notch is present.
React Native version: 0.59.8 (Expo 34.0.0)
Tested on Android
Steps To Reproduce
- Listen for
keyboardDidShow events
- Inspect the event details (note the
height and screenY properties in particular)
- Compare these values to
Dimensions.get('screen') and Dimensions.get('window')
Expected behaviour
The height property of the keyboardDidShow event reflects the correct height of the keyboard
Actual behaviour
The height that is returned is slightly smaller than the expected value: the difference seems to be the height of the notch. I assume that the screenY property (correctly) reflects the offset from the top of the screen (upper side of the notch), but the height is calculated using the window dimensions (everything under the notch). For phones that don't have a notch, the top of the screen and window are the same, so the height is correct. However, on phones with a notch, the top of the window is the bottom of the notch and as a result, the height is too small.
Example with actual numbers
Pixel 3 (no notch):
- screen height: 785
- window height: 737 (excludes on-screen system controls at the bottom of the screen, but includes status bar)
- keyboard screenY: 447
- keyboard height: 289
Pixel 3 XL (with notch):
- screen height: 845
- window height: 748 (excludes system controls and notch)
- keyboard screenY: 515
- keyboard height: 233
As you can see, screenY + keyboardHeight = windowHeight in both cases. As screenY is a screen coordinate, not window, this should be equal to screenHeight instead.
Snack: https://snack.expo.io/Sk_yXw9Sr
The height of the keyboard as reported by the
keyboardDidShowevent is wrong when a notch is present.React Native version: 0.59.8 (Expo 34.0.0)
Tested on Android
Steps To Reproduce
keyboardDidShoweventsheightandscreenYproperties in particular)Dimensions.get('screen')andDimensions.get('window')Expected behaviour
The
heightproperty of thekeyboardDidShowevent reflects the correct height of the keyboardActual behaviour
The height that is returned is slightly smaller than the expected value: the difference seems to be the height of the notch. I assume that the
screenYproperty (correctly) reflects the offset from the top of thescreen(upper side of the notch), but theheightis calculated using thewindowdimensions (everything under the notch). For phones that don't have a notch, the top of thescreenandwindoware the same, so theheightis correct. However, on phones with a notch, the top of thewindowis the bottom of the notch and as a result, the height is too small.Example with actual numbers
Pixel 3 (no notch):
Pixel 3 XL (with notch):
As you can see,
screenY + keyboardHeight = windowHeightin both cases. AsscreenYis ascreencoordinate, notwindow, this should be equal toscreenHeightinstead.Snack: https://snack.expo.io/Sk_yXw9Sr