Commit be7ef24
authored
fix: rely on screen dimensions instead of window dimensions (#948)
## 📜 Description
Rely on screen dimensions instead of window dimensions.
## 💡 Motivation and Context
Hook `useWindowDimensions` relies on `window` dimensions. Internally for
`window` react-native uses `[RCTKeyWindowValuesProxy
sharedInstance].windowSize` which may be not updated when screen gets
rotated (in some cases), while `mainScreen.bounds.size` (that is used
for `screen` dimensions) gets updated.
So it looks like it's better to rely on `screen` instead of `window` to
handle screen rotation cases.
Last, but not least: react-native subscribes to rotation events, but
doesn't call `beginGeneratingDeviceOrientationNotifications`. Without
invoking this function `useWindowDimensions` will not receive updates
when screen is getting rotated. At the moment it works, because other
libs (`expo-screen-orientation`, `react-native-screens` are calling this
method), but I think it also should be fixed in `react-native` core at
some point of time.
Closes
#915
## 📢 Changelog
<!-- High level overview of important changes -->
<!-- For example: fixed status bar manipulation; added new types
declarations; -->
<!-- If your changes don't affect one of platform/language below - then
remove this platform/language -->
### JS
- create custom implementation for `useWindowDimensions` for all
platforms except Android;
## 🤔 How Has This Been Tested?
Tested manually in repro app.
Verified additionally be e2e tests 🤞
## 📸 Screenshots (if appropriate):
|Before|After|
|-------|-----|
|||
## 📝 Checklist
- [x] CI successfully passed
- [x] I added new mocks and corresponding unit-tests if library API was
changed1 parent aa1fa7d commit be7ef24
1 file changed
Lines changed: 53 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
0 commit comments