fix: wrong useWindowDimensions on iPad#957
Merged
kirillzyusko merged 1 commit intomainfrom May 25, 2025
Merged
Conversation
Contributor
📊 Package size report
|
2 tasks
2 tasks
kirillzyusko
added a commit
that referenced
this pull request
Sep 8, 2025
## 📜 Description Use `window` size instead of `screen`. ## 💡 Motivation and Context Originally I added code in #948 (used subscription on `screen` instead of `window`). In #957 I realized that new approach has downsides and started to use `layoutSubviews` method instead of subscription to events that apple provides (and I kept using `screen` size as main source of truth). However on iPad in multi-task/stage-manager mode screen size may not reflect a real window size (because if window is floating it can be much smaller than the screen). So in this PR I'm refining solutions made in #948 and #957. We still need to use `window` as main source of truth and we need to read it in `layoutSubviews` because new dimensions may not be available in events that we receive from notification center. I tested repo provided in #948 and #957 and with new code they still seem to work well: |948|957| |----|----| |<video src="https://github.com/user-attachments/assets/80755323-dad0-49ef-8cde-916e1f3c525a">|<video src="https://github.com/user-attachments/assets/72b7b9e9-f385-45df-824e-c392f60f1af7">| Closes #1045 ## 📢 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 - read `window` dimensions instead of `screen`; ### iOS - use `self.window` instead of `UIScreen.main`; ## 🤔 How Has This Been Tested? Tested manually on iPad 11 Pro (m4, 16GB, iOS 18.5). ## 📸 Screenshots (if appropriate): |Before|After| |-------|-----| |<img width="1668" height="2420" alt="image" src="https://github.com/user-attachments/assets/d5ffe241-285a-44f5-869a-ac399308d281" />|<img width="1668" height="2420" alt="image" src="https://github.com/user-attachments/assets/59e73c7d-0618-4140-bec7-4547d9d29a2a" />| ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Add support for
windowDidResizeevent on iOS.💡 Motivation and Context
In #948 I changed implementation and added subscription to
screenvalues instead ofwindow.While it fixes some issues it doesn't work on iPad 🤯 This is very sad that such basic functionality can not be handled by RN out-of-the-box. However we already use own
useWindowDimensionshook on Android. So in this PR I decided to replicate that behavior on iOS.react-native-safe-area-contextdoesn't have that problem, butreact-native-safe-area-contexthandles that event inlayoutSubviews. After thinking a while I decided to use the same approach and emit eventwindowDidResize. And this approach actually works 🙂 I also added a check to not emit events too frequently if dimensions weren't changed.The PR #956 also aims to solve that problem, but
useWindowDimensionsis used by other components, such asKeyboardAvoidingView/KeyboardAwareScrollView, so the problem should be fixed in hook itself.Closes #955
📢 Changelog
iOS
windowDidResizeevent with device screen dimensions;🤔 How Has This Been Tested?
Tested manually in reproduction example + by e2e tests.
📸 Screenshots (if appropriate):
📝 Checklist