Skip to content

Commit

Permalink
Un-deprecate DisplayMetrics.getWindowDisplayMetrics() method
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mdvacca authored and facebook-github-bot committed Jul 26, 2022
1 parent 7db6c08 commit 4cbd263
Showing 1 changed file with 3 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 4cbd263

Please sign in to comment.