-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
[0.63.1][Android] Dimensions API stops working randomly after a while #29451
Comments
Update: Tried downgrading and this is definitely a 0.63.1 issue... I still don't know why would WebViews trigger it though. |
Can confirm! The issue appears very ranromly but frequently. On native screens the orientation changes are detected correctly. But after switching to a webview screen and rotating the device it stops working and the dimensions either stay in portrait or landscape mode. After that no orientation changes are detected anymore. On iOS we haven't had any problems. |
Those issues really seem related, although they seem to be getting the issue right away. From my testing, it only happens after opening a webview (or perhaps the webview uses something else that triggers it, such as a Modal/Dialog or screen navigation). This issue seems quite critical, any work-arounds at least? |
I have the same issue on my Application. Anyone has any workaround here ? |
There may definitely be some overlap with the issue we're having. Our app includes a module that uses UIWebView in its operation. I've not checked other screens, but the incorrect dimensions are definitely occurring on the screen that uses this library. We can't update the module to WKWebView so can't check if that also causes the issue, but there could be a connection. |
For me, this is happening on Android only, so I wouldn't know about UIWebView. I'm guessing most people implemented their app without rotation support, so they are not aware of this issue at all. For me, this is quite critical and needs urgent attention. |
Oh yes, you're right! We're having this issue on Android only, so it obviously has nothing to do with the iOS stuff. I'm definitely having one of those days... :) It's a complete blocker for us upgrading as well, unfortunately. |
@fabriziobertoglio1987 I know you have been getting your hands dirty by debugging some very deep react native bugs. Sorry about tagging you here, but do you have any ideas what could be this bug? Seems like extremely serious since it cripples Android apps. |
Thanks a lot @cristianoccazinsp currently I only have weeekends to do opensource, unluckily I never worked with the ReactNative Dimensions SourceCode My todos for next weeks are finishing #29117 and #29070 Then I can take a look at this. Does it really need Webview and react-navigation to reproduce?
What does Mounting, Unmounting, Rotating actually do to stop the event to fire? Can we get insight on the source-code and how does WebView, ReactNavigation affect the rotation/event firing? But N.1, reproducing the bug without React-Navigation and Webview, because this exclude a large amount of sourcecode from investigation It is much easier to remove a prop So the easiest way to solve the bug is by testing the RN API and see the difference in the reproduction. I bookmarked and follow this issue, I'll try to solve it once finishing #29117 and #29070 are completed. Thanks. I wish you a good day |
I will try to test a fresh project to discard webviews and navigation causing issues. But it really seems like something internal from RN is breaking in a very bad way and I don't really see how other libraries could affect it. |
Repro here: https://github.com/cristianoccazinsp/react-native-dims-bug Although the webview seems needed to trigger the bug, I believe it is something related to either surface handling or event emitters (that the webview use), but technically any component could trigger the bug. Running the above example: just run it on android and rotate the device a few times, dimensions will stop updating right away. |
I also encountered this issue while handling rotation detection with a web view - it happens immediately on the first render. In my case, a call to The packages used:
A strange behavior worth noting: When changing to a separate tab in my app (using Also, referencing this issue from |
Thanks for the insight @TGibsonn . For now, we have decided to roll back to RN 0.62.2 until this and other major bugs are resolved. |
Is there anything new regarding this issue? Anything we can do in order to help? This seems to block teams wanting to update to latest RN version right now :/ |
As far as I know, we can only wait and stay with 0.61.x . This hasn't brought a lot of attention because most apps use locked rotation and I guess rarely use webviews. |
@fabriziobertoglio1987 Can't provide too much information at the moment, but I can confirm we're also getting this issue for Android only on 0.63.2. We'll be having to rollback the RN update 😞 . Happy to provide info where I can. We do use react-native-webview, but it's not loaded on screen before we get this issue. I wonder if pointing out this library though is just a red herring. |
Still an issue, and RN 0.64 is just around the corner. This issue could really use some attention since migration is impossible until this is resolved and apps will already lag behind with RN updates. |
possibly related - the 'change' listener doesn't fire at all 0.63.3 iOS Simulator, traced it from onLayout not firing on orientation change. |
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
- map size will now be fixed, independent of orientation - this needs to be done due to a bug in react-native 0.63 (facebook/react-native#29451) SVA-86
- map size will now be fixed, independent of orientation - this needs to be done due to a bug in react-native 0.63 (facebook/react-native#29451) SVA-86
@luisnaranjo733 Thanks for letting us know that the fix has been added to 0.63.4. Would you possibly know who I can get in contact with to get WalmartLabs hosted Android Maven repo updated? |
There's yet another issue when combined with react-native-webview on iOS. When rendering a webview that has a video player, if the user enters fullscreen and then rotates the device, |
I actually face this issue at RN 0.59.9. Dimension 'screen' works while 'window' doesnt when rotating the screne in video player webview (react-native-youtube-iframe 1.4.1). |
Does anyone know if this has been resolved with 0.64.0? |
@nickfujita - apologies, I don't actually know how to go about doing that. What I do know is that this fix is available in 0.63.4 as well as 0.64.0 @cristianoccazinsp - this fix is definitely deployed in 0.64.0, assuming we are talking about the same one. You mentioned something about iOS, if that's the case, that sounds like a totally unrelated thing because the fix I pushed for was very Android specific. |
Unfortunately I'm still seeing this issue with 0.64.0. It's android only, and happens pretty consistently, but only after a WebView has been loaded. Oddly enough, it doesn't happen in 0.63.4, so this may be a new bug not addressed by the aforementioned PRs. |
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
Still seeing this in 64.1 too. |
@jmsbrett this is fixed in 64.2. I didn't realize how RN branching worked when I pushed for this to get cherry-picked into 63. I thought that landing it in the master branch was enough for it to naturally flow back into the 64 release, but I was wrong. This is why the first few 64 releases didn't include the fix. https://github.com/facebook/react-native/releases/tag/v0.64.2
|
This comment has been minimized.
This comment has been minimized.
Since commit landed in 64 I guess we can close this off? |
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
I'm having this issue in RN 65.1. |
@RemyMachado I was having an issue with the Dimensions API and ended up using react-native-orientation-locker. Maybe test your component and supplement the Dimensions API with react-native-orientation-locker to get a baseline? I am not a maintainer so I really do not know the underlying work of the Dimensions API but from my research RN orientation-locker actually works by listening to the device directly and does not abstract it to an API. |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This issue was closed because it has been stalled for 7 days with no activity. |
Please provide all the information requested. Issues that do not follow this format are likely to stall.
Description
Using
Dimensions.get('window')
andDimensions.addEventListener(...)
stops working/firing events randomly after a while.I can't figure out exactly what triggers the issue, but after the event listener stops firing, calling
get
will also return incorrect values (e.g., portrait values even if in landscape). Note that the actual UI still works as expected (rotates/adjusts), but the Dimensions API just completely breaks.After testing for a couple of hours, the bug seems to happen after a WebView is loaded (with https://github.com/react-native-community/react-native-webview). I can't tell yet whether this was caused by an upgrade in the WebView library or react native itself. I will be linking this issue there as well.
React Native version:
Run
react-native info
in your terminal and copy the results here.Steps To Reproduce
Provide a detailed list of steps that reproduce the issue.
Dimensions.get('window')
andDimensions.addEventListener(...)
. For example, registering these on the root's component mount.<WebView />
component and rotate a few times<WebView />
componentDimensions.get(...)
always return the same values (i.e., they do not update when the UI rotates).Some logcat warnings when the issue triggers:
Note: react-navigation is also being used.
Expected Results
Dimensions API should not stop updating just because a possibly buggy component (WebView) is messing with the app.
Snack, code example, screenshot, or link to a repository:
Please provide a Snack (https://snack.expo.io/), a link to a repository on GitHub, or provide a minimal code example that reproduces the problem.
You may provide a screenshot of the application if you think it is relevant to your bug report.
Here are some tips for providing a minimal example: https://stackoverflow.com/help/mcve
The text was updated successfully, but these errors were encountered: