Files
react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/PixelUtil.java
T
David Vacca 8b5e3fc16b Update size of Root ShadowNode when RootView changes its size
Summary: This diff updates the size of RootShadowNode and re-render RN views when the Size of the Android React View changes

Reviewed By: achen1

Differential Revision: D9173758

fbshipit-source-id: 7cc6bbfb646025c3ec1773ab041eb9207623af71
2018-08-28 23:03:34 -07:00

66 lines
1.5 KiB
Java

/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.uimanager;
import android.util.TypedValue;
/**
* Android dp to pixel manipulation
*/
public class PixelUtil {
/**
* Convert from DIP to PX
*/
public static float toPixelFromDIP(float value) {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
value,
DisplayMetricsHolder.getWindowDisplayMetrics());
}
/**
* Convert from DIP to PX
*/
public static float toPixelFromDIP(double value) {
return toPixelFromDIP((float) value);
}
/**
* Convert from SP to PX
*/
public static float toPixelFromSP(float value) {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP,
value,
DisplayMetricsHolder.getWindowDisplayMetrics());
}
/**
* Convert from SP to PX
*/
public static float toPixelFromSP(double value) {
return toPixelFromSP((float) value);
}
/**
* Convert from PX to DP
*/
public static float toDIPFromPixel(float value) {
return value / DisplayMetricsHolder.getWindowDisplayMetrics().density;
}
/**
* @return {@link float} that represents the density of the display metrics for device screen.
*/
public static float getDisplayMetricDensity() {
return DisplayMetricsHolder.getScreenDisplayMetrics().density;
}
}