Use new DisplayMetrics object in getDisplayMetrics as to not overwrite Android global state

Summary:
The change in 8e603940e3 actually causes a super bad bug when `context.getResources().getDisplayMetrics()` is accessed in other parts of the application.

It turns out that when you dive into the impl of `getRealMetrics`, it mutates whatever `DisplayMetrics` object is passed to it. In this case, `getDisplayMetrics` ends up mutating the `DisplayMetrics` object that sits on the application context's `Resources` instance.

This PR makes that not so.

/cc jesseruder ide jaysoo bestander astreet
Closes https://github.com/facebook/react-native/pull/5764

Reviewed By: svcscm

Differential Revision: D2902386

Pulled By: androidtrunkagent

fb-gh-sync-id: 3f24b68bc7e6b4ca83808c03ef3637e1ac9a673e
This commit is contained in:
Adam Miskiewicz
2016-02-05 06:28:20 -08:00
committed by facebook-github-bot-4
parent fef4196c8b
commit 6ac007b2ba

View File

@@ -464,7 +464,8 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
private DisplayMetrics getDisplayMetrics() {
Context context = getReactApplicationContext();
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
DisplayMetrics displayMetrics = new DisplayMetrics();
displayMetrics.setTo(context.getResources().getDisplayMetrics());
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();