Skip to content

Commit 6ac007b

Browse files
skevyfacebook-github-bot-4
authored andcommitted
Use new DisplayMetrics object in getDisplayMetrics as to not overwrite Android global state
Summary: The change in facebook@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 facebook#5764 Reviewed By: svcscm Differential Revision: D2902386 Pulled By: androidtrunkagent fb-gh-sync-id: 3f24b68bc7e6b4ca83808c03ef3637e1ac9a673e
1 parent fef4196 commit 6ac007b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ public void sendAccessibilityEvent(int tag, int eventType) {
464464
private DisplayMetrics getDisplayMetrics() {
465465
Context context = getReactApplicationContext();
466466

467-
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
467+
DisplayMetrics displayMetrics = new DisplayMetrics();
468+
displayMetrics.setTo(context.getResources().getDisplayMetrics());
468469
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
469470
Display display = wm.getDefaultDisplay();
470471

0 commit comments

Comments
 (0)