Skip to content

Commit

Permalink
Use new DisplayMetrics object in getDisplayMetrics as to not overwr…
Browse files Browse the repository at this point in the history
…ite Android global state

Summary:
The change in 8e60394 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 #5764

Reviewed By: svcscm

Differential Revision: D2902386

Pulled By: androidtrunkagent

fb-gh-sync-id: 3f24b68bc7e6b4ca83808c03ef3637e1ac9a673e
  • Loading branch information
skevy authored and facebook-github-bot-4 committed Feb 5, 2016
1 parent fef4196 commit 6ac007b
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ public void sendAccessibilityEvent(int tag, int eventType) {
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();

Expand Down

0 comments on commit 6ac007b

Please sign in to comment.