-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dimensions.get('window') is not returning the current values on Android #29323
Comments
have you tried the newer useWindowDimensions()? |
I haven't yet. Seems handy, but our app is all class components so we can't use it without rewriting them or wrapping them in function components. |
I can confirm. On Android the event listener won't trigger on orientation change. It makes no difference if we use |
onLayout seems to have changed behavior in 0.63 but I'm not sure exactly how. It's breaking my app on iOS only right now by failing to call onLayout when a parent element resize causes a child element to move on the screen. Seems likely related to this issue. What changed with onLayout in 0.63? |
weirdly, when using |
Yes, it not work with android !! |
I can confirm it is not working on android, but on iOS is it still ok. Using RN 0.63.2. Probably also happening on 0.63.3, I will try to update later. This has broken my orientation-dependent rendering, I had to check the 'screen' dimensions to get the correct orientation change but I see a lag in the orientation layout change after device rotation of about 2-3 seconds (only on android). |
This comment has been minimized.
This comment has been minimized.
This one is pretty mild, it has only been open for 3 months. There are outstanding bugs going on 4 years without solutions. There's a lot of undocumented, inconsistent-across-platforms, or (especially on Android) broken stuff in RN. FB has developed somewhat of a reputation for subpar community management with this project. Many issues get closed without resolution or explanation. PRs linger for months or years. Long standing bugs never get fixed/merged because FB has closed internal workarounds. etc, etc. I'm not complaining however, it's free software, we can fork and fix it ourselves if the quirks bother us. It's just a shame to see an innovative and otherwise great project like RN marred and slowed by seemingly indifferent maintainers. As for a fix, I've found that many measurement problems on Android are corrected by doing two things:
|
@react-native-bot This is the really critical issue which breaks all Android orientation related styling in apps. When this can be reviewed by maintainers? Thanks... |
Summary: Currently the dimensions are created once, and then cached. This change will reload the dimensions when the device orientation changes to insure that dimension update events follow orientation changed events. this should help address the following issues, that I know of: #29105 #29451 #29323 ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Android] [Fixed] - Dimension update events are now properly sent following orientation change Pull Request resolved: #30324 Test Plan: Open up RNTester app. Select the Dimensions API list item. Rotate the device and verify that the dimensions are correct based on orientation. Reviewed By: fkgozali Differential Revision: D24874733 Pulled By: ejanzer fbshipit-source-id: 867681ecb009d368a2ae7b67d94d6355e67dea7b
The fix for this is checked into the master branch (thank you @ajpaulingalls and @ejanzer) and will naturally make its way into the first react-native@0.64 release candidates. |
Summary: Currently the dimensions are created once, and then cached. This change will reload the dimensions when the device orientation changes to insure that dimension update events follow orientation changed events. this should help address the following issues, that I know of: facebook#29105 facebook#29451 facebook#29323 ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Android] [Fixed] - Dimension update events are now properly sent following orientation change Pull Request resolved: facebook#30324 Test Plan: Open up RNTester app. Select the Dimensions API list item. Rotate the device and verify that the dimensions are correct based on orientation. Reviewed By: fkgozali Differential Revision: D24874733 Pulled By: ejanzer fbshipit-source-id: 867681ecb009d368a2ae7b67d94d6355e67dea7b
Summary: Currently the dimensions are created once, and then cached. This change will reload the dimensions when the device orientation changes to insure that dimension update events follow orientation changed events. this should help address the following issues, that I know of: #29105 #29451 #29323 ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Android] [Fixed] - Dimension update events are now properly sent following orientation change Pull Request resolved: #30324 Test Plan: Open up RNTester app. Select the Dimensions API list item. Rotate the device and verify that the dimensions are correct based on orientation. Reviewed By: fkgozali Differential Revision: D24874733 Pulled By: ejanzer fbshipit-source-id: 867681ecb009d368a2ae7b67d94d6355e67dea7b
Summary: Currently the dimensions are created once, and then cached. This change will reload the dimensions when the device orientation changes to insure that dimension update events follow orientation changed events. this should help address the following issues, that I know of: facebook#29105 facebook#29451 facebook#29323 ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Android] [Fixed] - Dimension update events are now properly sent following orientation change Pull Request resolved: facebook#30324 Test Plan: Open up RNTester app. Select the Dimensions API list item. Rotate the device and verify that the dimensions are correct based on orientation. Reviewed By: fkgozali Differential Revision: D24874733 Pulled By: ejanzer fbshipit-source-id: 867681ecb009d368a2ae7b67d94d6355e67dea7b
I'd like to note that my issue about the dimensions API is still actual, and dimensions is not working good with (at least) a split-screen feature, my issue is #30371 and it's still broken on 0.63.4(as I just tested), since the patch mentioned above was included in 0.63.4 I expected it to work, but it didn't do a thing to me. Also let me know if I should close my issue(react with 👀), since this one seems to be the same. Can anyone else also confirm the issue being present in 0.63.4, or am I trippin |
any solution for this issue? |
Hi |
@martingg88 @jcabrerazuniga #30371 (comment) might be pretty helpful for certain cases |
Dimensions.get('screen') still doen'tt update when rotating device. I have to close/reopen the app to get it to update. RN version 0.64 |
Hello, |
Summary: Currently the dimensions are created once, and then cached. This change will reload the dimensions when the device orientation changes to insure that dimension update events follow orientation changed events. this should help address the following issues, that I know of: facebook#29105 facebook#29451 facebook#29323 ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Android] [Fixed] - Dimension update events are now properly sent following orientation change Pull Request resolved: facebook#30324 Test Plan: Open up RNTester app. Select the Dimensions API list item. Rotate the device and verify that the dimensions are correct based on orientation. Reviewed By: fkgozali Differential Revision: D24874733 Pulled By: ejanzer fbshipit-source-id: 867681ecb009d368a2ae7b67d94d6355e67dea7b (cherry picked from commit 0e9296b)
Summary: Currently the dimensions are created once, and then cached. This change will reload the dimensions when the device orientation changes to insure that dimension update events follow orientation changed events. this should help address the following issues, that I know of: facebook#29105 facebook#29451 facebook#29323 <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Android] [Fixed] - Dimension update events are now properly sent following orientation change Pull Request resolved: facebook#30324 Test Plan: Open up RNTester app. Select the Dimensions API list item. Rotate the device and verify that the dimensions are correct based on orientation. Reviewed By: fkgozali Differential Revision: D24874733 Pulled By: ejanzer fbshipit-source-id: 867681ecb009d368a2ae7b67d94d6355e67dea7b
Summary: Currently the dimensions are created once, and then cached. This change will reload the dimensions when the device orientation changes to insure that dimension update events follow orientation changed events. this should help address the following issues, that I know of: #29105 #29451 #29323 ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Android] [Fixed] - Dimension update events are now properly sent following orientation change Pull Request resolved: #30324 Test Plan: Open up RNTester app. Select the Dimensions API list item. Rotate the device and verify that the dimensions are correct based on orientation. Reviewed By: fkgozali Differential Revision: D24874733 Pulled By: ejanzer fbshipit-source-id: 867681ecb009d368a2ae7b67d94d6355e67dea7b
This is still an issue in 64.1. |
Hi, is there any fix? still its not working for me on android |
Summary: When retrieving the device dimensions through the JS `Dimensions` utility, the result of `Dimensions.get` can be incorrect on Android. ### Related issues - #29105 - #29451 - #29323 The issue is caused by the Android `DeviceInfoModule` that provides initial screen dimensions and then subsequently updates those by emitting `didUpdateDimensions` events. The assumption in that implementation is that the initial display metrics will not have changed prior to the first check for updated metrics. However that is not the case as the device may be rotated (as shown in the attached video). The solution in this PR is to keep track of the initial dimensions for comparison at the first check for updated metrics. ## Changelog [Android] [Fixed] - Fix Dimensions not updating Pull Request resolved: #31973 Test Plan: ### Steps to reproduce 1. Install the RNTester app on Android from the `main` branch. 2. Set the device auto-rotation to ON 3. Start the RNTester app 4. While the app is loading, rotate the device 5. Navigate to the `Dimensions` screen 6. Either a. Observe the screen width and height are reversed, or b. Quit the app and return to step 3. ### Verifying the fix #### Manually Using the above steps, the issue should no longer be reproducible. #### Automatically See unit tests in `ReactAndroid/src/test/java/com/facebook/react/modules/deviceinfo/DeviceInfoModuleTest.java` ### Video https://user-images.githubusercontent.com/4940864/128485453-2ae04724-4ac5-4267-a59a-140cc3af626b.mp4 Reviewed By: JoshuaGross Differential Revision: D30319919 Pulled By: lunaleaps fbshipit-source-id: 52a2faeafc522b1c2a196ca40357027eafa1a84b
Summary: When retrieving the device dimensions through the JS `Dimensions` utility, the result of `Dimensions.get` can be incorrect on Android. - facebook#29105 - facebook#29451 - facebook#29323 The issue is caused by the Android `DeviceInfoModule` that provides initial screen dimensions and then subsequently updates those by emitting `didUpdateDimensions` events. The assumption in that implementation is that the initial display metrics will not have changed prior to the first check for updated metrics. However that is not the case as the device may be rotated (as shown in the attached video). The solution in this PR is to keep track of the initial dimensions for comparison at the first check for updated metrics. [Android] [Fixed] - Fix Dimensions not updating Pull Request resolved: facebook#31973 Test Plan: 1. Install the RNTester app on Android from the `main` branch. 2. Set the device auto-rotation to ON 3. Start the RNTester app 4. While the app is loading, rotate the device 5. Navigate to the `Dimensions` screen 6. Either a. Observe the screen width and height are reversed, or b. Quit the app and return to step 3. Using the above steps, the issue should no longer be reproducible. See unit tests in `ReactAndroid/src/test/java/com/facebook/react/modules/deviceinfo/DeviceInfoModuleTest.java` https://user-images.githubusercontent.com/4940864/128485453-2ae04724-4ac5-4267-a59a-140cc3af626b.mp4 Reviewed By: JoshuaGross Differential Revision: D30319919 Pulled By: lunaleaps fbshipit-source-id: 52a2faeafc522b1c2a196ca40357027eafa1a84b
Summary: When retrieving the device dimensions through the JS `Dimensions` utility, the result of `Dimensions.get` can be incorrect on Android. - facebook#29105 - facebook#29451 - facebook#29323 The issue is caused by the Android `DeviceInfoModule` that provides initial screen dimensions and then subsequently updates those by emitting `didUpdateDimensions` events. The assumption in that implementation is that the initial display metrics will not have changed prior to the first check for updated metrics. However that is not the case as the device may be rotated (as shown in the attached video). The solution in this PR is to keep track of the initial dimensions for comparison at the first check for updated metrics. [Android] [Fixed] - Fix Dimensions not updating Pull Request resolved: facebook#31973 Test Plan: 1. Install the RNTester app on Android from the `main` branch. 2. Set the device auto-rotation to ON 3. Start the RNTester app 4. While the app is loading, rotate the device 5. Navigate to the `Dimensions` screen 6. Either a. Observe the screen width and height are reversed, or b. Quit the app and return to step 3. Using the above steps, the issue should no longer be reproducible. See unit tests in `ReactAndroid/src/test/java/com/facebook/react/modules/deviceinfo/DeviceInfoModuleTest.java` https://user-images.githubusercontent.com/4940864/128485453-2ae04724-4ac5-4267-a59a-140cc3af626b.mp4 Reviewed By: JoshuaGross Differential Revision: D30319919 Pulled By: lunaleaps fbshipit-source-id: 52a2faeafc522b1c2a196ca40357027eafa1a84b
Updated to 0.63.4 from 0.63.3, and confirmed fixed on Android. |
My problem on 0.61.5 was not that the values were not correct, but that the view was not re-rendered at all after the rotation, so I added this to the constructor() and it worked:
|
Description
The width and height returned by Dimensions.get('window') are not updating. The first time it's called, it returns the correct values. But if I change the device screen orientation and call it again, it returns the same values as before. This only happens on Android, and only started happening after I upgraded from RN 0.62.2 to 0.63.0
React Native version:
0.63.0
Android only
Steps To Reproduce
Provide a detailed list of steps that reproduce the issue.
onLayout={() => { console.log(Dimensions.get('window')); }
Expected Results
The width and height should update to reflect the new screen layout
The text was updated successfully, but these errors were encountered: