From 4cbd263173b992c0a0dc7c640e39794f39ce1b34 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Mon, 25 Jul 2022 17:48:14 -0700 Subject: [PATCH] Un-deprecate DisplayMetrics.getWindowDisplayMetrics() method Summary: The purpose of this diff is to un-deprecate the method DisplayMetrics.getWindowDisplayMetrics(). As React Native is used in devices with multiple screens and displays, we need to provide a non-deprecated way to access display metrics (e.g. screen density) for the window that's used to render react native views. This diff doesn't make any change in behavior, but it un-deprecates the API changelog: [Android][Added] Un-deprecate DisplayMetrics.getWindowDisplayMetrics() method Reviewed By: javache Differential Revision: D37871954 fbshipit-source-id: d8eb97cfae096f2f62ed1389a6de17a892a46b43 --- .../react/uimanager/DisplayMetricsHolder.java | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/DisplayMetricsHolder.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/DisplayMetricsHolder.java index c3a2c630563f04..2d9d1def01c9fb 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/DisplayMetricsHolder.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/DisplayMetricsHolder.java @@ -18,21 +18,13 @@ /** * Holds an instance of the current DisplayMetrics so we don't have to thread it through all the - * classes that need it. Note: windowDisplayMetrics are deprecated in favor of ScreenDisplayMetrics: - * window metrics are supposed to return the drawable area but there's no guarantee that they - * correspond to the actual size of the {@link ReactRootView}. Moreover, they are not consistent - * with what iOS returns. Screen metrics returns the metrics of the entire screen, is consistent - * with iOS and should be used instead. + * classes that need it. */ public class DisplayMetricsHolder { private static @Nullable DisplayMetrics sWindowDisplayMetrics; private static @Nullable DisplayMetrics sScreenDisplayMetrics; - /** - * @deprecated Use {@link #setScreenDisplayMetrics(DisplayMetrics)} instead. See comment above as - * to why this is not correct to use. - */ public static void setWindowDisplayMetrics(DisplayMetrics displayMetrics) { sWindowDisplayMetrics = displayMetrics; } @@ -63,11 +55,7 @@ public static void initDisplayMetrics(Context context) { DisplayMetricsHolder.setScreenDisplayMetrics(screenDisplayMetrics); } - /** - * @deprecated Use {@link #getScreenDisplayMetrics()} instead. See comment above as to why this is - * not correct to use. - */ - @Deprecated + /** Returns the metrics of the window associated to the Context used to initialize ReactNative */ public static DisplayMetrics getWindowDisplayMetrics() { return sWindowDisplayMetrics; } @@ -76,6 +64,7 @@ public static void setScreenDisplayMetrics(DisplayMetrics screenDisplayMetrics) sScreenDisplayMetrics = screenDisplayMetrics; } + /** Screen metrics returns the metrics of the default screen on the device. */ public static DisplayMetrics getScreenDisplayMetrics() { return sScreenDisplayMetrics; }