feat: own useWindowDimensions
hook
#468
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📜 Description
Implemented own
useWindowDimensions
hook for Android.💡 Motivation and Context
The problem with default implementation of
useWindowDimensions
on Android is that it doesn't work well withedge-to-edge
mode and you can not retrieve an actual size of the screen. Here is a brief comparison of values captured on my device (Pixel 7 Pro).Translucent
StatusBar
:Non translucent
StatusBar
:So as you can see it doesn't react properly on the case when
StatusBar
is translucent and reports incorrect values, which later on causes incorrect layout calculation in components likeKeyboardAvoidingView
orKeyboardAwareScrollView
.Theoretically we could workaround this problem by original
useWindowDimensions().height + StatusBar.currentHeight
, but everything become trickier when we add translucentnavigationBar
(+ translucentstatusBar
):In this case derived value
useWindowDimensions().height + StatusBar.currentHeight
(867.4285888671875) still will produce incorrect value and all calculations will be broken. So I decided to create own version of the hook which will cover all the cases.Issue for reference: facebook/react-native#41918
Closes #434 #334
📢 Changelog
JS
useWindowDimensions
hook;useWindowDimensions
inKeyboardAwareScrollView
andKeyboardAvoidingView
components;useWindowDimensions
hook as default RN implementation;Android
WindowDimensionsListener
class;ThemedReactContext.content
extension;ThemedReactContext.setupWindowDimensionListener
extension;🤔 How Has This Been Tested?
Tested manually on Pixel 7 Pro (API 34).
Tested on CI via e2e (API 28).
📸 Screenshots (if appropriate):
Pixel 7 Pro (Android 14),
KeyboardAwareScrollView
:KeyboardAwareScrollView
KeyboardAvoidingView
📝 Checklist