react-native-macos/ReactAndroid
Jonathan Andrew c18a492858 Fix Dimensions not updating on Android (#31973)
Summary:
When retrieving the device dimensions through the JS `Dimensions` utility, the result of `Dimensions.get` can be incorrect on Android.

### Related issues

- https://github.com/facebook/react-native/issues/29105
- https://github.com/facebook/react-native/issues/29451
- https://github.com/facebook/react-native/issues/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: https://github.com/facebook/react-native/pull/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
2021-08-17 18:10:31 -07:00
..
libs Upgrade Android support library to version 28 in RN 2019-01-22 10:44:53 -08:00
src Fix Dimensions not updating on Android (#31973) 2021-08-17 18:10:31 -07:00
.npmignore Don't publish /ReactAndroid/build to npm, update version on master 2015-10-12 11:11:40 -07:00
Android-prebuilt.mk Implement and integrate Mapbuffer 2021-03-24 03:52:31 -07:00
DevExperience.md Updating the URLs to point at new domain name reactnative.dev 2020-02-24 13:09:11 -08:00
README.md docs: Fix dead links in README for rn-tester (#31901) 2021-07-27 11:01:47 -07:00
build.gradle Migrate to androidx.autofill.HintConstants & Support all constant types (#28008) 2021-07-21 15:14:41 -07:00
gradle.properties RN: Replace `master` with `main` in Documentation 2021-07-15 15:22:57 -07:00
proguard-rules.pro Remove Okhttp3 Android Proguard Rules (#30514) 2020-12-17 09:41:17 -08:00

README.md

Building React Native for Android

See the docs on the wiki.

Running tests

When you submit a pull request CircleCI will automatically run all tests. To run tests locally, see Testing.