Skip to content

Commit

Permalink
Save a copy of DisplayMetrics native map in DeviceInfoModule
Browse files Browse the repository at this point in the history
Summary:
After some more testing, I discovered a problem in D19395326 because the native map that DeviceInfoModule was storing in `mPreviousDisplayMetrics` had been consumed when the event was emitted to JS. This caused the comparison to fail, so it would emit the event again when the dimensions hadn't changed.

In this diff, I'm storing a Java-only copy of the native map before emitting the event to JS so this shouldn't happen.

Changelog: [Android][Fixed] Fix bug in updating dimensions in JS

Reviewed By: mdvacca

Differential Revision: D19462861

fbshipit-source-id: 2e47479df93377b85fe87f255972dd31e874e3a8
  • Loading branch information
Emily Janzer authored and facebook-github-bot committed Jan 18, 2020
1 parent cc3e27d commit bef845f
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ public void emitUpdateDimensionsEvent() {
WritableNativeMap displayMetrics =
DisplayMetricsHolder.getDisplayMetricsNativeMap(mFontScale);
if (!displayMetrics.equals(mPreviousDisplayMetrics)) {
mPreviousDisplayMetrics = displayMetrics.copy();
mReactApplicationContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("didUpdateDimensions", displayMetrics);
mPreviousDisplayMetrics = displayMetrics;
}
} else {
ReactSoftException.logSoftException(
Expand Down

0 comments on commit bef845f

Please sign in to comment.